Skip to content

Instantly share code, notes, and snippets.

@hramos
Created July 26, 2016 19:09
Show Gist options
  • Save hramos/feb1cfc437f4da2c785b716d3a8f16be to your computer and use it in GitHub Desktop.
Save hramos/feb1cfc437f4da2c785b716d3a8f16be to your computer and use it in GitHub Desktop.
Subclassing PFObject
@interface Armor : PFObject<PFSubclassing>
+ (NSString *)parseClassName;
@end
// Import this header to let Armor know that PFObject privately provides most
// of the methods for PFSubclassing.
#import <Parse/PFObject+Subclass.h>
@implementation Armor
+ (void)load {
[self registerSubclass];
}
+ (NSString *)parseClassName {
return @"Armor";
}
@end
class Armor : PFObject, PFSubclassing {
override class func initialize() {
struct Static {
static var onceToken : dispatch_once_t = 0;
}
dispatch_once(&Static.onceToken) {
self.registerSubclass()
}
}
static func parseClassName() -> String {
return "Armor"
}
}
// Import this header into your Swift bridge header file to
// let Armor know that PFObject privately provides most of
// the methods for PFSubclassing.
#import <Parse/PFObject+Subclass.h>
@giusecapo
Copy link

If I try to subclass with Swift 4 I get "Method 'initialize()' defines Objective-C class method 'initialize', which is not permitted by Swift"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment