为了能让类的成员变量正确的被外接访问,我们需要设置set和get方法。
- @property (nonatomic,retain)NSString *test1;
- @property (nonatomic,copy)NSString *test2;
成员变量的属性不同(retain,copy)相对于的set方法也不同:
- @implementation SecondViewController
- - (void)setTest1:(NSString *)test
- {
-
- [test retain];
- if (_test1 != nil) {
- [_test1 release];
- }
-
-
- _test1 = test;
- }
- - (void)setTest2:(NSString *)test
- {
- if (_test2 != nil) {
- [_test2 release];
- }
-
-
- _test2 = [test copy];
- }
iOS set方法
原文:http://www.cnblogs.com/spiderdzl/p/4121015.html