1
我從Parse獲取對象並將其顯示在我的UI中。現在我正在將數據保存在Parse的Local DataStorage中。我看了下面的解析示例:如何從Parse獲取多個對象以保存Swift中的本地DataStorage?
let query = PFQuery(className: "GameScore")
query.fromLocalDatastore()
query.getObjectInBackgroundWithId("xWMyZ4YE").continueWithBlock {
(task: BFTask!) -> AnyObject in
if let error = task.error {
// Something went wrong.
return task;
}
// task.result will be your game score
return task;
}
以上示例用於獲取1個對象。我不知道如何爲多個對象做同樣的事情。我通過我下面的代碼獲取的對象:
let query:PFQuery = PFQuery(className: "Events")
query.findObjectsInBackgroundWithBlock {
(object, error) -> Void in
if object != nil
{
if(object!.count != 0)
{
for messageObject in object! {
let eventName:String? = (messageObject as! PFObject)["EventName"] as? String
let createdBy:String? = (messageObject as! PFObject)["CreatedBy"] as? String
let eventDate:String? = (messageObject as! PFObject)["EventDate"] as? String
objModalClass.eveName = eventName!
objModalClass.crtedBy = createdBy!
objModalClass.eveVenue = eventVenue!
}
}
}
}
在我上面的代碼中,我怎麼能保存所有提取的對象objModalClass
在本地數據存儲。請詳細解釋。