我有一个PFObject子类SomeClass,我添加了一个方法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
但在致电后
[object iconImageName]
我得到了
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PFObject iconImageName]: unrecognized selector sent to instance 0x174133b00'
我可以确认该对象确实是SomeClass
当我使用类方法+
时也会发生这种情况答案 0 :(得分:4)
根据documentation,你忽略了一些子类规则:
创建
PFObject
子类:
1.声明符合PFSubclassing
协议的子类 2.实现类方法parseClassName
。这是您传递给initWithClassName:
的字符串,并生成所有未来的类名 参考不必要 3.在.m文件中导入PFObject+Subclass
。这将实现PFSubclassing
之后的parseClassName
中的所有方法 4.在解析[YourClass registerSubclass]
之前致电setApplicationId:clientKey:
。
尽量满足您的课程规则。
示例:
// 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