Description
Say we have a custom user subclass:
class TUser: PFUser {
override class func initialize() {
struct Static {
static var onceToken : dispatch_once_t = 0;
}
dispatch_once(&Static.onceToken) {
self.registerSubclass()
}
}
// MARK: Parse Properties
@NSManaged var mySpecialObject: PFObject?
}
The expectation is that TUser.currentUser() will return the currently authenticated user as a TUser object. Unfortunately, we often get a PFUser object back instead, and the method ignores our subclass altogether.
When trying to access a property like TUser.currentUser()?.mySpecialObject
this causes a bad access crash, because PFObject does not have a mySpecialObject property.
I tried to do a little digging and got all the way to the PFObjectFilePersistenceController
and the PFObjectFileCoder
where it appears to write the current user info to Core Data, and it stores the Parse class name (_User in our case) but doesn't seem to do anything for subclassing. Following the call tree up, I don't see anywhere that a subclass would get instantiated instead and returned.
How is this supposed to work? Is the issue stemming from creating these subclasses using Swift? Is the Parse SDK expecting something dynamic that Swift isn't providing?