`
lizhuang
  • 浏览: 888434 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
copy retain 体会NSString的copy属性
@interface Demo : NSObject
{
    NSString *retainString;
    NSString *copyString;
}

@property (nonatomic, retain)NSString *retainString;
@property (nonatomic, copy)NSString *copyString;
@end

@implementation Demo
@synthesize retainString;
@synthesize copyString;
-(void)dealloc
{
    [retainString release];
    [copyString release];
    [super dealloc];
}

@end

Demo *o = [[Demo alloc] init];
NSMutableString *s1 = [[NSMutableString alloc] initWithCapacity:100];
[s1 setString:@"fuckyou"];
o.retainString = s1;
o.copyString = s1;
NSLog(@"retain string is %@", o.retainString);
NSLog(@"copy string is %@", o.copyString);
[s1 setString:@"fuckme"];
NSLog(@"retain string is %@", o.retainString);
NSLog(@"copy string is %@", o.copyString);
Global site tag (gtag.js) - Google Analytics