最近因为某些蛋疼的原因,开始接触一些 IOS OC相关的玩意。今天踩到一个小小小坑。
关于Objective C 的property,定义如下
@interface OCClass:NSObject
{
id data;
NSString* name;
}
-(id)initWithString:(NSString*)aName;
@property int count;
+(OCClass*)createMyClassWithString:(NSString*)aName;
@end
这里有三个需要注意的地方:
【1】自动生成方法
@synthesize xxx,那么系统会自动生成getXxx和setXxx方法,注意,第一个X是大写的。
【2】手动生成get,set方法
@dynamic count,那么是需要你手动指定set和get方法,那么应该是:
-(int)getCount{}
-setCount:(int)value{}
【3】注意大小写......
而我非常蛋疼的写成了setcount和getcount,则调用的时候,报错,unrecognized selector sent to instance