Reputation: 11362
Just upgraded to Swift 2 and using Xcode 7. Using Parse for backend.
I'm doing a normal query in background:
let query = PFQuery(className: "User")
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if let objects = objects as? [PFObject] {
}
}
I get error in Xcode:
Downcast from '[PFObject]?' to '[PFObject]' only unwraps optionals; did you mean to use '!'?
Any ideas how I can fix this?
Upvotes: 0
Views: 510
Reputation: 73
Just remove as? [PFObject]
Parse Change the [AnyObject] to a [PFObject]
findObjectsInBackgroundWithBlock({(objects:[AnyObject]?, error:NSError?)
so :
findObjectsInBackgroundWithBlock { (objects, error)
The Downcast is not required
Upvotes: 2
Reputation: 61
Change your code into:
let query = PFQuery(className: "User");
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
if let objects = objects as! [PFObject] {
}
}
Upvotes: 0