@property (nonatomic,copy) NSMutableString * addressName;
self.addressName = [NSMutableString string];
for (NSString *name in self.headerTitleArray) {
[self.addressName appendString:name];
}
自己很纳闷为什么明明创建的是NSMutableString,还会报错,上网查了资料
The problem is due to the copy attribute on your property. When you assign a value to the property, it creates a copy. But the copy is made with copy and not mutableCopy so you actually end up assigning an NSString to the property and not an NSMutableString.
Get rid of copy on the property or implement your own custom "setter" method that calls mutableCopy.
结果我就重写了
set方法
- (void)setAddressName:(NSMutableString *)addressName
{
_addressName = [addressName mutableCopy];
}
因为属性没有mutableCopy,所以实际还是copy