leibie
申明
@interface NSString(NumberConvenience)
-(NSNumber *)lenthAsNumber;
@end
实现
@implementation NSString(NumberConvenience)
-(NSNumber *)lenthAsNumber{
unsigned int length = [self length];
return ([NSNumber numberWithUnsignedint : length]);
}
@end
正式协议
申明
@protocol myprotocol
-(id) someprotocol : (NSString *)zone;
@optional
-(void)method1;
@required
-(void)mthod2;
@end
采用
@interface myClass: NSOject<myprotocol, otherprotocol>
{
}
@end
特性
申明 @property(attributes) type name;
@interface myclass : someclass
{
int someproperty;
}
@property int someproperty;
@property float otherproperty;
@end
实现
@implementation myclass
@synthesize someproperty;
@synthesize property1 = otherproperty;
@end
object-c 学习小记
最新推荐文章于 2024-07-10 20:12:39 发布