Reputation: 821
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
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()
}
Upvotes: 0
Views: 1442
Reputation: 2012
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
Upvotes: 3