0

I have a PFObject Subclass SomeClass, to which i added a method iconImageName

.h

@interface SomeClass : PFObject

@property (nonatomic, strong) NSDictionary * availableAttributes;

@property (nonatomic, strong) NSString * type;

- (NSString *)iconImageName;

@end

.m

@implementation SomeClass

@dynamic availableAttributes;
@dynamic type;

+ (NSString *)parseClassName {
    return NSStringFromClass([self class]);
}

- (NSString *)iconImageName {
    return [NSString stringWithFormat:@"icon-type-%@", self.type];
}

@end

but after calling

[object iconImageName] i get

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PFObject iconImageName]: unrecognized selector sent to instance 0x174133b00'

i can confirm that the object is indeed SomeClass

this also happens when i use a class method +

0

1 Answer 1

4

According to documentation you ignored some subclassing rules:

To create a PFObject subclass:
1. Declare a subclass which conforms to the PFSubclassing protocol.
2. Implement the class method parseClassName. This is the string you would pass to initWithClassName: and makes all future class name references unnecessary.
3. Import PFObject+Subclass in your .m file. This implements all methods in PFSubclassing beyond parseClassName.
4. Call [YourClass registerSubclass] before Parse setApplicationId:clientKey:.

Try to satisfy this rules for your class.

Example:

// Armor.h
@interface Armor : PFObject<PFSubclassing>
+ (NSString *)parseClassName;
@end

// Armor.m
// 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
Sign up to request clarification or add additional context in comments.

1 Comment

Sneaky Parse, I totally missed the [className registerSubclass] thing. @PeterLapisu, you're saying you were able to put that inside the subclass' implementation, though? Calling self? The instructions there say that it has to be done before you initialize Parse, but I can see that being false / outdated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.