Subclass PFUser in swift

前端 未结 2 1965
盖世英雄少女心
盖世英雄少女心 2021-01-07 08:45

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.

Pars

相关标签:
2条回答
  • 2021-01-07 09:08

    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"
    }
    
    0 讨论(0)
  • 2021-01-07 09:20

    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()
            }
        }
    
    0 讨论(0)
提交回复
热议问题