[英]empty value on cast PFObject to subclass in cellForRowAtIndexPath
[英]PFObject unable to be cast to custom subclass
在最近更新swift編譯器更新之前,此代碼工作正常。 我已經糾正了所有明顯的錯誤,但由於某種原因,當我運行應用程序時,它在for in loop
崩潰時嘗試將[AnyObject]
為我的自定義Memory
類。
日志和錯誤顯示如下:
Has connectivity
Successfully retrieved 8 memories.
current memory: <Memories: 0x170120960, objectId: AO3EvPFob4, localId: (null)> {
ACL = "<PFACL: 0x174047e30>";
Date = "3915-04-08 05:00:00 +0000";
Guests = 4;
Title = test4;
}
Could not cast value of type 'PFObject' (0x100130bc0) to 'MemoryVault.Memory' (0x10012fa00).
所以我知道我正在從Parse中檢索到8個正確的記憶,而且當前的記憶是正確的......它只是不會施放它。
編碼:
if (NetworkValidator.hasConnectivity()){ // Has internet connectivity
println("Has connectivity")
Memory.memoryQuery().findObjectsInBackgroundWithBlock{
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
// The find succeeded.
println("Successfully retrieved \(objects!.count) memories.")
Memory.unpinAllInBackground(self.memories, block: {
(success: Bool, error: NSError?) -> Void in
// Clear current list
self.memories = [Memory]()
// Do something with the found objects
for memory in objects! {
println("current memory: \(memory)")
let currentMemory: Memory = memory as! Memory
// Save to localDataStore
currentMemory.pinInBackground()
println("\(currentMemory.memoryTitle) from Parse")
// Append to current
self.memories.append(currentMemory)
}
})
// Notify tableView to reload data
self.memoriesTableView.reloadData()
} else {
// Log details of the failure
println("Error: \(error!) \(error!.userInfo)")
}
}
}
這個讓我忙碌幾個小時 - Parse-Documentation提到:
PFObject的強類型子類必須符合PFSubclassing協議,並且必須在調用[Parse setApplicationId:clientKey:]之前調用。“
通過在AppDelegate中調用MyParseClass.registerSubclass() ,我解決了我的問題!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.