Subclass PFUser in swift

醉酒当歌 提交于 2019-12-19 11:22:50

问题


I wanna subclass the PFUser object in swift. I also want to declare my own variables. The Parse documentation on subclassing do not cover PFUser at this point.

Parse documentation on subclassing PFObject:

class Armor : PFObject, PFSubclassing {
    class func load() {
       self.registerSubclass()
    }
    class func parseClassName() -> String! {
       return "Armor"
    }
}

回答1:


BridgingHeader.h:

#import <Parse/Parse.h>
#import <Parse/PFObject+Subclass.h>

User.swift:

import Foundation

class User : PFUser, PFSubclassing {

override class func load() {
    self.registerSubclass()
}

//My variables
dynamic var firstname: String
dynamic var lastname: String

}

DONT´T include this snippet when subclassing PFUser:

class func parseClassName() -> String! {
    return "User"
}



回答2:


In Swift 2.0 You not need to implement PFSubclassing Protocol for Subclassing PFUser.

Just create normal subclass like this;

class ParseUser: PFUser {

    @NSManaged var name: String?
    @NSManaged var surname: String?
    @NSManaged var phoneNumber: String?

    override class func initialize() {
        struct Static {
            static var onceToken : dispatch_once_t = 0;
        }
        dispatch_once(&Static.onceToken) {
            self.registerSubclass()
        }
    }


来源:https://stackoverflow.com/questions/25388865/subclass-pfuser-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!