合成访问器方法有一个复制属性,例如:
@property (copy) NSMutableString *string;
使用此 setter 方法进行分配时,它似乎总是调用 copy 方法,即使我想string
在分配实例变量期间创建我分配给的内容的可变副本string
。
这是一个已知问题,是否有任何解决方法?
谢谢 :-)
合成访问器方法有一个复制属性,例如:
@property (copy) NSMutableString *string;
使用此 setter 方法进行分配时,它似乎总是调用 copy 方法,即使我想string
在分配实例变量期间创建我分配给的内容的可变副本string
。
这是一个已知问题,是否有任何解决方法?
谢谢 :-)
Don't call @synthesize string
in your .m implementation file and instead write your own getter.
e.g.
- (NSMutableString *) string
{
NSMutableString * stringToReturn = [NSMutableString stringWithString: someStringObject];
}
More information about properties (and what to do when you don't do @synthesize
) can be found at:
p.s. the property name "string" may be confusing to anyone else who looks at your code down the road... I'd recommend changing that to be more program-specific