简体   繁体   中英

Retrieving CreatedAt Data From Parse - Swift

I want to retrieve the createdAt column data from parse via swift. But somehow I am getting a "unexpectedly found nil while unwrapping an Optional value" error. I am using the below code to retrieve the data, when I uncomment the createdAT part, the rest data is retrieved well in my app. Attached I added a view of the parse class. Thank you very much

http://imgur.com/QR6Kl5v

query.findObjectsInBackgroundWithBlock {
    (objects:[AnyObject]?, error:NSError?) -> Void in

    if error == nil {

    for object in objects! {

        self.resultsNameArray.append(object.objectForKey("profileName") as! String)

        self.resultsUserNameArray.append(object.objectForKey("userName") as! String)

        self.resultsImageFiles.append(object.objectForKey("relUserPointer")!.objectForKey("photo") as! PFFile)

        self.resultsTweetArray.append(object.objectForKey("tweet") as! String)

        self.resultsDateArray.append(object.objectForKey("createdAt") as! NSDate)

        self.resultsTable.reloadData()

    }

The standard properties of a PFObject are not accessible through the objectForKey: method, instead you should used the property createdAt .


A small example: Here a query was done with findObjectsInBackgroundWithBlock , where the returning array of results is called result :

let object: AnyObject = result!.first!
println("property: \(object.createdAt)")
let tmp: AnyObject? = object.objectForKey("createdAt")
println("objectForKey: \(tmp)")

The output from this is the following lines:

property: Optional(2015-05-01 10:46:54 +0000)
objectForKey: nil

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM