这通常应该是简单而直接的,但我很难找到答案。我希望能够将objectId分配给一个数组,所以当我想更新一个列时,我可以使用query.getObjectInBackgroundWithId
。我正在执行初始查询并将找到的值分配给字典。不幸的是,当我尝试分配列objectId并且得到fatal error: unexpectedly found nil while unwrapping an Optional value
var query = PFQuery(className:"classname")
query.whereKey("available", equalTo:true)
query.findObjectsInBackgroundWithBlock( {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
println("Successfully retrieved \(objects!.count)")
if let objects = objects as? [PFObject] {
for object in objects {
let x = dict(aColumn1: (object["column1"] as! String), aColumn2: (object["column2"] as! String), aId: (object["objectId"] as! String))
dictArr.append(x)
}
}
} else {
// Log details of the failure
println("Error: \(error!) \(error!.userInfo!)")
}
}
)
答案 0 :(得分:0)
尝试像这样创建数组:
let x = [(object["column1"] as! String),(object["column2"] as! String), (object["objectId"] as! String)]
但似乎更像是你想要一本字典,如果是这种情况你可以试试这个:
let x = [("aColumn1": (object["column1"] as! String), "aColumn2": (object["column2"] as! String), "aId": (object["objectId"] as! String))]