Parse File Query and Swift 1.2 Error - getDataInBackgroundWithBlock

I am trying to request images from Parse, and I continue to work in fatal error: unexpectedly found nil while unwrapping optional value. I'm not sure if this is due to a recent update to Swift and Xcode, so maybe this is at the end of Parse or it could be a user error.

Only those getDataInBackGroundWithBlockwill take values NSData?and NSError?as optional. If I try to expand them or use other types, it will not compile.

PFQueryreturns data as expected. This is only when trying to switch from PFFileto NSDatato a call getDataInBackGroundWithBlockthat arose from the problem.

The frame is connected and running. I tested it quite a bit.

Here is the call stack: enter image description here

12 . . , Swift Xcode, .

, , :

Parse " "

Parse and Swift 1.2 issue

Parse getDataInBackgroundWithBlock

Parse sdk -

Parse docs:

https://www.parse.com/docs/ios_guide#files/iOS ( )

var photoArray: Array<UIImage> = []


override func viewDidLoad() {
    super.viewDidLoad()

    callPFObjectQuery()

    let testObject = PFObject(className: "QuestionMaster") //testobject
    testObject["foo"] = "bar" //testobject
    testObject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
        println("Object has been saved.")

    }
} 

func callPFObjectQuery() {

    var finalObjects: [PFObject] = []
    var nsdataObjects: NSData?

    var query: PFQuery = PFQuery(className: "QuestionMaster")
    query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in

        for object in objects! {

            let imageFiles = object["questionImage"] as! PFFile!

//error line     imageFiles.getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in

                    if error == nil {

                        dispatch_async(dispatch_get_main_queue()) {

                            let image = UIImage(data: imageData!)
                            self.photoArray.append(image!)
                            println(self.photoArray[0])

                        }

                    }

                }
            }

        }
    }

, 12 2015 . - Swift 1.2: , , 1 . - , , , . , , (6-8k ) Parse SDK Swift. , . Uttam Sinha , getDataInBackGroundWithBlock . , . Ingouackaz for-loop, getDataInBackGroundWithBlock .

, , , . , , PFObject. , getDataInBackGroundWithBlock .

object["questionImage"] , , object.valueForKey("questionImage"), . "questionImage" , .

PDF Parse. . , , . , .

0
4

. . , . , .

, imageFiles.getDataInBackgroundWithBlock. . @user2770692 .

func queryImages() {

    var query: PFQuery = PFQuery(className: "QuestionMaster")
    query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in

        for object in objects! {

            let imageFiles = object["questionImage"] as! PFFile

            println(imageFiles)

            imageFiles.getDataInBackgroundWithBlock({
                (imageData: NSData?, error: NSError?) -> Void in
                if (error == nil) {
                    let image = UIImage(data:imageData!)
                    println(image)
                }

            })

        }

    }
}
0

Swift 1.2

file.getDataInBackgroundWithBlock({
                (imageData: NSData?, error: NSError?) -> Void in
                if (error == nil) {
                    let image = UIImage(data:imageData!)
                    println(image)
                }

            })
+2

. -

query.findObjectsInBackgroundWithBlock ({(objects:[AnyObject]!, error: NSError!) in
        if(error == nil){

            self.getImageData(objects as [PFObject])

        }
        else{
            println("Error in retrieving \(error)")
        }

    })//findObjectsInBackgroundWithblock - end


func getImageData(objects: [PFObject]) {
    for object in objects {

        let thumbNail = object["questionImage"] as PFFile

        println(thumbNail)

        thumbNail.getDataInBackgroundWithBlock({
            (imageData: NSData!, error: NSError!) -> Void in
            if (error == nil) {
                let image = UIImage(data:imageData)                
                println(image)
            }

        })//getDataInBackgroundWithBlock - end

    }//for - end
}
0

"!" :

 let imageFiles = object["questionImage"] as! PFFile!

:

 let imageFiles = object["questionImage"] as! PFFile
0

All Articles