我想通过 swift 从解析中检索 createdAt 列数据。但不知何故,我收到“在展开可选值时意外发现 nil”错误。我正在使用下面的代码检索数据,当我取消注释 createdAT 部分时,其余数据在我的应用程序中检索得很好。附件我添加了一个解析类的 View 。非常感谢
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()
}
最佳答案
PFObject
的标准属性不能通过 objectForKey:
方法访问,您应该使用 createdAt
属性。
一个小示例:这里使用 findObjectsInBackgroundWithBlock
完成查询,其中返回的结果数组称为 result
:
let object: AnyObject = result!.first!
println("property: \(object.createdAt)")
let tmp: AnyObject? = object.objectForKey("createdAt")
println("objectForKey: \(tmp)")
它的输出是以下几行:
property: Optional(2015-05-01 10:46:54 +0000)
objectForKey: nil
关于ios - 从 Parse 检索 CreatedAt 数据 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30695047/