0

Xcode 6.3 '[AnyObject]?' does not have a member named 'Generator'

Error from this line "for object2 in objects2{"

            let findImage:PFQuery = PFQuery(className: "_User")
            findImage.whereKey("objectId", containedIn: self.userlist as [AnyObject])
            findImage.findObjectsInBackgroundWithBlock{
                (objects2:[AnyObject]?, error2:NSError?)->Void in
                //var recordProfileImg:NSMutableArray = NSMutableArray()
                if !(error2 != nil){
                    for object2 in objects2{
                        println(objects2.count)
                        let sweet:PFObject = object2 as PFObject
                        if sweet.objectForKey("profileImage") != nil{
                            var recordProfileImg:NSMutableArray = [sweet.objectId,sweet.objectForKey("profileImage") as PFFile]
                            self.userImageList.addObject(recordProfileImg)

                            // println(userImageList)
                        }
                    }
                }
            }

This is the link of picture. http://imageshack.com/a/img537/3446/DzQiad.png

3 Answers3

1

Since objects2 is an optional, you have to unwrap it. If you're sure it won't be nil, try this:

for object2 in objects2! {
rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • And if you aren't? Trying to understand why ```if let``` doesn't work in this case. – Shmidt Jul 26 '15 at 00:34
  • 1
    The easiest solution would be `for object2 in objects2 ?? [] { ... }`, which will substitute an empty array if `objects2` is nil. – rob mayoff Jul 26 '15 at 03:03
0

Use ! after your array :

for info in array! {

        }
Alok
  • 24,880
  • 6
  • 40
  • 67
-1

Had the same issue after Xcode updgrade, figured it out.
First, you don't need the Types in the parameter list after latest update of XCode (something changed there).

    query.findObjectsInBackgroundWithBlock( { (myItems, error) -> Void in
    ...

Second, you need to add the ! in the for loop for your list of items (in the example below myItems!). So your code should be similar to this:

    query.findObjectsInBackgroundWithBlock( { (myItems, error) -> Void in
        if error == nil {
            for item in myItems! {
                let itemToWorkWith = item as! PFObject
                ...
Jón Andri
  • 176
  • 1
  • 6