I am building an IOS app in swift 2.0 in xCode Beta. I built a custom user class which subclasses PFUser, relevant excerpts of the class are reproduced below
import UIKit
class User: PFUser, Entity {
// MARK: - Declare Field Variables
@NSManaged var firstName : String
@NSManaged var lastName : String
//Several other state variables follow in the same format
///initializing a new person
init (firstName: String, lastName: String, password: String, email: String) {
super.init()
super.username = email
super.password = password
super.email = email
//set initial key-value pairs for person
self.firstName = firstName
self.lastName = lastName
// Special method to sign up new user
super.signUp()
}
// Additional methods placed here
// MARK: - Conformation to PFObjectSubclassing
override class func initialize() {
self.registerSubclass()
}
// MARK: - Conformation to Entity
func saveToDatabase() {
//Saves the new PFObject Asyncronously
self.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
if (success) { print("User \(self.username) succesfully saved to database.") }
else { print(error) }
}
}
}
Using the parse GUI, I verified that Users were successfully saved to the database.
I am attempting to retrieve the data using a class written in the Appdelegate, that is called from the Appdelegate as follows:
var examplePerson: User!
func funcThatIsCalled() {
var query : PFQuery = PFUser.query()!
var people = query.findObjects()
self.examplePerson = people![0] as! User
}
This returns the error:
"Could not cast value of type 'PFUser' (0x108326490) to 'MyPersonalApp.User' (0x108323f80)."
Adding User.registerSublass() to the Appdelegate as follows:
User.registerSubclass()
// Initialize Parse.
Parse.setApplicationId("myAppID",
clientKey: "MyClientKey")
results in the error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The class PFUser must be registered with registerSubclass before using Parse.'