标签:oc
#import "Dog.h"
@implementation Dog
- (id)copyWithZone:(NSZone *)zone
{
Dog *dog = [[Dog allocWithZone:zone] init];
dog.name = self.name;
return dog;
}
@end
#import <Foundation/Foundation.h>
#import "Dog.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
//copy方法
NSMutableArray *marr = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",nil];
NSArray *arr = [marr copy];
//mutableCopy方法, 用于获取一个可变对象
Dog *dog = [[Dog alloc] init];
NSMutableString *mstr = [[NSMutableString alloc] initWithString:@"ahua"];
dog.name = mstr;
Dog *anthorDog = [dog copy];
anthorDog.name = @"1212";
// Dog *anthorDog = [Dog new];
NSLog(@"dog name = %@ anthorDog name=%@",dog.name,anthorDog.name);
}
return 0;
}
标签:oc
原文地址:http://blog.csdn.net/wp1198571320/article/details/46374781