Search code examples
swiftparse-platformpfquery

swift parse query skip null column


I'm doing a PFQuery to get uploaded file in column. How to get that file and if the column is null there's no file do something else ?

If the column is null i'm getting error message the query wont go well.

fatal error: unexpectedly found nil while unwrapping on Optional value

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

            if error == nil
            {
                for object in objects! {
                    self.files.append(object.objectForKey("file") as! PFFile)     
                }

I want to get that file but if the column was null do something else ? how can i do that?


Solution

  • Use optional unwrapping with if let file = ... as? PFFile {

    } else {

    }