方法1.直接赋值: NSString *str1 = @"my string";
方法2.类函数初始化生成: NSString *str2 = [NSString stringWithString:str1];
方法3.实例方法初始化生成: NSString *str3 = [[NSString alloc] initWithString:@"my string"];
NSString *str4 = [[NSString alloc]initWithFormat:@"my string"];
NSLog(@"---%p",str1);
NSLog(@"---%p",str2);
NSLog(@"---%p",str3);
NSLog(@"---%p",str4);
运行结果;
2013-10-14 10:27:02.650 hfjhdfjdhf[897:c07] ---0x46ac
2013-10-14 10:27:02.651 hfjhdfjdhf[897:c07] ---0x46ac
2013-10-14 10:27:02.651 hfjhdfjdhf[897:c07] ---0x46ac
2013-10-14 10:27:02.652 hfjhdfjdhf[897:c07] ---0x75c2360
请问谁能回答下他们的区别?
|