I have just downloaded and experimented with Parse.
Everything works as expected, but I have a question regarding a good subclassing design.
The standard PFUser has THREE fields by default.
I would like to add a few more "column" to the User table. Those are:
Below is my subclass design, but I am not sure if this is the way one might want to subclass their PFUser.
import UIKit
class GPUser: PFUser, PFSubclassing {
var firstName: String? {
didSet {
self["firstName"] = firstName;
}
}
var lastName: String? {
didSet {
self["lastName"] = lastName;
}
}
var phone: String? {
didSet {
self["phone"] = phone;
}
}
var profilePicture: PFFile? {
didSet {
self["profilePicture"] = profilePicture;
}
}
}
Questions:
I am wondering what is the best approach to subclass a PFUser (in order to add columns to it) and of course the best design possible. Do you have any design in mind?
should we override the init method and instantiate all of the variables (firstName, lastName, phone, etc) so that the optional fields column get created on signUp?
Should I get rid of those didSets blocks? If yes, could you suggest on a better design?
In my opinion, the easiest way to achieve what you want is to use stored @NSManaged
properties:
class GPUser: PFUser, PFSubclassing {
@NSManaged var firstName: String
@NSManaged var lastName: String
@NSManaged var phone: String
@NSManaged var profilePicture: PFFile
class func parseClassName() -> String! {
return "YourParseClassName"
}
}
Don't forget to register for your custom PFUser
class in the AppDelegate
:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
GPUser.registerSubclass()
}