标签:
使用copy
#import <Foundation/Foundation.h>
@interface Person : NSObject
//外界改变时, 不会影响当前字符串.
@property (nonatomic ,copy)NSString *name;
@end
#import "Person.h"
@implementation Person
-(void)setName:(NSString *)name{
_name = [name copy];
}
@end
使用strong
#import <Foundation/Foundation.h>
@interface Person : NSObject
@property (nonatomic ,strong)NSString *name;
@end
#import "Person.h"
@implementation Person
-(void)setName:(NSString *)name{
_name = name;
}
@end
在外界进行赋值时,不会进行判断,直接将传递进来的字符串进行赋值.
在实际应用中,我们可以通过传递不同类型的字符串,并打印内存地址来证明.
标签:
原文地址:http://www.cnblogs.com/zhoudaquan/p/5034187.html