Objective-C 类别使用
来源:互联网 发布:mac 系统怎么翻墙 编辑:程序博客网 时间:2024/05/21 10:01
1、目录结构:
2、CategoryThing.h:
//// CategoryThing.h// consoloTest//// Created by 侯家奇 on 16/8/17.// Copyright © 2016年 侯家奇. All rights reserved.//#ifndef CategoryThing_h#define CategoryThing_h#import <Foundation/Foundation.h>@interface CategoryThing : NSObject { NSInteger thing1; NSInteger thing2; NSInteger thing3;}@end@interface CategoryThing (Thing1)- (void) setThing1:(NSInteger)thing1;- (NSInteger) thing1;@end@interface CategoryThing (Thing2)- (void) setThing2:(NSInteger)thing2;- (NSInteger) thing2;@end@interface CategoryThing (Thing3)- (void) setThing3:(NSInteger)thing3;- (NSInteger) thing3;@end#endif /* CategoryThing_h */
3、CategoryThing.m:
//// CategoryThing.m// consoloTest//// Created by 侯家奇 on 16/8/17.// Copyright © 2016年 侯家奇. All rights reserved.//#import "CategoryThing.h"@implementation CategoryThing- (NSString *) description { NSString *desc; desc = [NSString stringWithFormat:@"%ld %ld %ld", (long)thing1, (long)thing2, (long)thing3]; return (desc);}@end
4、Thing1.m:
//// Thing1.m// consoloTest//// Created by 侯家奇 on 16/8/17.// Copyright © 2016年 侯家奇. All rights reserved.//#import "CategoryThing.h"@implementation CategoryThing (Thing1)- (void) setThing1:(NSInteger)t1 { thing1 = t1;}- (NSInteger) thing1 { return (thing1);}@end
5、Thing2.m:
//// Thing2.m// consoloTest//// Created by 侯家奇 on 16/8/17.// Copyright © 2016年 侯家奇. All rights reserved.//#import "CategoryThing.h"@implementation CategoryThing (Thing2)- (void) setThing2:(NSInteger)t2 { thing2 = t2;}- (NSInteger) thing2 { return (thing2);}@end
6、Thing3.m:
//// Thing3.m// consoloTest//// Created by 侯家奇 on 16/8/17.// Copyright © 2016年 侯家奇. All rights reserved.//#import "CategoryThing.h"@implementation CategoryThing (Thing3)- (void) setThing3:(NSInteger)t3 { thing3 = t3;}- (NSInteger) thing3 { return (thing3);}@end
7、main.m:
#import "CategoryThing.h"int main (int argc, const char *argv[]) { @autoreleasepool { CategoryThing *thing = [[CategoryThing alloc] init]; [thing setThing1:5]; [thing setThing2:23]; [thing setThing3:42]; NSLog(@"Things are %@", [thing description]); } return (0);}
8、结果:
0 0
- Objective-C 类别使用
- objective-c category类别的使用
- Objective-c类别
- Category 类别 -Objective-C
- Category 类别 -Objective-C
- Objective-c类别
- Category 类别 -Objective-C
- Objective-C语言--类别
- Category 类别 -Objective-C
- Category 类别 -Objective-C
- Objective-C 类别小结
- Objective-C中的类别(Category)的使用
- 类别(objective-c基础笔记)
- Objective-c Category(类别)
- objective-c总结12-类别
- Objective-C 类别(Category)浅谈
- Objective-C 类别(Category)浅谈
- Objective-C类别(catagory)
- Valid Sudoku
- Java 中Timer和TimerTask 定时器和定时任务使用的例子
- 【leetcode】216. Combination Sum III
- javah类不存在
- eclipse环境配置maven项目
- Objective-C 类别使用
- Hive on Spark源码分析(六)—— RemoteSparkJobMonitor与JobHandle
- 防止出现 Capturing 'self' strongly in this block is likely to lead to a retain cycle [duplicate]
- poj 3009 Curling2.0(dfs)
- 初学Hibernate经验
- 用户体验之自定义Toast,拿过来直接用(Toast的重复显示)
- poj 1159Palindrome(dp lcs变形)
- js遍历数组的方法
- colo.xml