什么是copy
常见的复制有:文件复制
特点:
OC中的copy
如何使用copy功能
使用copy功能的前提
@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end
@protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; @end
NSString *srcStr = @"lnj"; NSString *copyStr = [srcStr copy]; NSLog(@"src = %p, copy = %p", srcStr, copyStr);
NSString *srcStr = @"lnj"; NSMutableString *copyStr = [srcStr mutableCopy]; NSLog(@"src = %p, copy = %p", srcStr, copyStr); NSLog(@"src = %@, copy = %@", srcStr, copyStr); [copyStr appendString:@" cool"]; NSLog(@"src = %@, copy = %@", srcStr, copyStr);
NSMutableString *srcStr = [NSMutableString stringWithFormat:@"lnj"]; NSString *copyStr = [srcStr copy]; [srcStr appendString:@" cool"]; NSLog(@"src = %p, copy = %p", srcStr, copyStr); NSLog(@"src = %@, copy = %@", srcStr, copyStr);
NSMutableString *srcStr = [NSMutableString stringWithFormat:@"lnj"]; NSMutableString *copyStr = [srcStr mutableCopy]; [srcStr appendString:@" cool"]; [copyStr appendString:@" 520it"]; NSLog(@"src = %p, copy = %p", srcStr, copyStr); NSLog(@"src = %@, copy = %@", srcStr, copyStr);
原文:http://www.cnblogs.com/xufengyuan/p/6648775.html