标签:
1 #import “UIViewController.h” 2 @interface UIViewController(CustomView) 3 -(void)extMethod; 4 @end
1 #import “UIViewController+CustomView.h” 2 @implementation UIViewController(CustomView) 3 -(void)extMethod; 4 @end
1 @interface MyObject:NSObject 2 { 3 NSNumber* number; 4 } 5 -(NSNumber*)getNum; 6 @end 7 8 @interface MyObject(Setter) 9 -(void)setNum:(NSNumber*)num; 10 @end 11 12 @implementation MyObject 13 -(NSNumber*)getNum 14 { 15 return number; 16 }
1 @interface MyObject:NSObject 2 { 3 NSNumber* number; 4 } 5 -(NSNumber*)getNum; 6 @end 7 8 @interface MyObject() //注意这里的括号里面是没有名字的 9 -(void)setNum:(NSNumber*)num; 10 @end 11 12 @implementation MyObject 13 -(NSNumber*)getNum 14 { 15 return number; 16 } 17 18 -(void)setNum:(NSNumber*)num 19 { 20 number = num; 21 } 22 @end
setNum是必须要实现,不然编译器会提出警告。
iOS - 类别和扩展(Categories和Extensions)
标签:
原文地址:http://www.cnblogs.com/baitongtong/p/5982043.html