ios - AnyObject does not have a member named generator -


i don't have enough reputation post images

the problem when did following

for object in objects { eg: ....

// [anyobject] not have member named generator - shows me error

}

and after search in stackoverflow , other sites did this:

if objects?.count > 0 {  object in objects! {  self.resultsusernamearray.append(object.username) -> error "cannot invoke append argument list of type (string?!)"  }  } else {  } 

[anyobject] not have member named generator || cannot invoke append argument list of type (string?!)

import uikit  var username = ""  class usersviewcontroller: uiviewcontroller, uitableviewdelegate, uitableviewdatasource {  @iboutlet weak var resultstable: uitableview!  var resultsusernamearray = [string]() var resultsprofilenamearray = [string]() var resultsimagefiles = [pffile]()  override func viewdidload() {     super.viewdidload()      let thewidth = view.frame.size.width     let theheight = view.frame.size.height      resultstable.frame = cgrectmake(0, 0, thewidth, theheight - 64)      username = pfuser.currentuser()!.username!  }    override func viewdidappear(animated: bool) {     super.viewdidappear(animated)      let predicate = nspredicate(format: "username !="+username+"'")     var query = pfquery(classname: "_user", predicate: predicate)      var objects = query.findobjects()      object in objects { // [anyobject] not have member named generator          self.resultsusernamearray.append(object.username)         self.resultsprofilenamearray.append(object["profilename"] as! string)         self.resultsimagefiles.append(object["photo"] as! pffile)          resultstable.reloaddata()      }  }   func tableview(tableview: uitableview, numberofrowsinsection eg..... { } 

help me please

query.findobjects() produces [anyobject]? (i.e. optional [anyobject]). so, if result query.findobjects() nil not conform generator protocol. so, first check whether result nil , unwrap it.

your other problem respect self.resultsusernamearray.append(object.username) object anyobject , not have property name username. first need cast object pfuser , use username property.

var objects = query.findobjects() if objects != nil {  // or use objects.count > 0     object in objects! {         if let user = object as? pfuser {             resultsusernamearray.append(user.username!)             ...         }     } } 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -