This code was working fine before the recent update to the swift compiler update. I have corrected all the obvious errors, but for some reason when I run the app now it crashes in the for in loop
when trying to cast [AnyObject]
to my custom Memory
class.
The log and error shows as follows:
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).
So I know I'm retrieving 8 correct memories from Parse, and the current memory is correct...it just wont cast it.
The code:
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)")
}
}
}
this one kept me busy some hours - Parse-Documentation mentions:
Strongly-typed subclasses of PFObject must conform to the PFSubclassing protocol and must call before [Parse setApplicationId:clientKey:] is called."
By calling MyParseClass.registerSubclass() in AppDelegate I got my issues fixed!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With