Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse - Subclassing with Swift?

I'm trying to get a standard subclassing to work with swift.

Bridging-Header.h

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

Subclass

class Event: PFObject, PFSubclassing {

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

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

getting a compile error saying that Event does not conform to PFSubclassing.

Any suggestions?

like image 767
aryaxt Avatar asked Dec 07 '25 03:12

aryaxt


1 Answers

Check out my Parse Subclass generator GSParseSchema. It can generate the Swift and Objective-C classes for you.

In Swift, you'll want to override the initialize function.

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

I've found this auto-registration to not always work, so I also explicitly register the subclasses in my AppDelegate. Be sure you register you before you initialize Parse with setApplicationId:clientKey:

Event.registerSubclass()
like image 55
dhallman Avatar answered Dec 08 '25 16:12

dhallman