- //创建可变字符串
- NSMutableString *str = [NSMutableString string];
- //设定字符串的内容
- str.string = @"zhangsan";
- //创建对象
- Person *person = [Person new];
- //给person的实例变量赋值
- person.name = str;
- //修改字符串内容
- [str appendString:@"xxxx"];
- NSLog(@"name = %@",person.name);
- NSLog(@"str = %@",str);
复制代码
为什么运行结果是:
name = zhangsanxxxx
str = zhangsanxxxx
而不是:
name = zhangsan
str = zhangsanxxxx |
|