Skip to content

Instantly share code, notes, and snippets.

@hunterbridges
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hunterbridges/eaae29b4d331c7d310ab to your computer and use it in GitHub Desktop.
Save hunterbridges/eaae29b4d331c7d310ab to your computer and use it in GitHub Desktop.
#import "PFObject+SubclassInit.h"
@implementation PFObject (SubclassInit)
+ (instancetype)subclass
{
Class klass = self;
SEL selector = @selector(parseClassName);
if ([klass respondsToSelector:selector]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
NSString *className = [klass performSelector:selector];
#pragma clang diagnostic pop
return [[self alloc] initWithClassName:className];
} else {
NSException *exc = [[NSException alloc] initWithName:NSInternalInconsistencyException
reason:@"Not a PFSubclassing class"
userInfo:nil];
[exc raise];
return nil;
}
}
+ (instancetype)subclassWithoutDataWithObjectId:(NSString *)objectId
{
Class klass = self;
SEL selector = @selector(parseClassName);
if ([klass respondsToSelector:selector]) {
SEL selector = @selector(objectWithoutDataWithObjectId:);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
return [klass performSelector:selector withObject:objectId];
#pragma clang diagnostic pop
} else {
NSException *exc = [[NSException alloc] initWithName:NSInternalInconsistencyException
reason:@"Not a PFSubclassing class"
userInfo:nil];
[exc raise];
return nil;
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment