NSMutableString 和设置访问器方法 Objective-C 2.0
合成访问器方法有一个复制属性,例如:
@property (copy) NSMutableString *string;
当使用此 setter 方法进行分配时,它似乎总是调用复制方法,即使我想创建分配给 string
的内容的可变副本,在实例变量string
赋值期间。
这是一个已知问题吗?有解决方法吗?
谢谢 :-)
There is a copy attribute for synthesised accessor methods ex:
@property (copy) NSMutableString *string;
When assign using this setter method it seems to always call the copy method, even though I would like to create a mutable copy of what ever I assign to string
, during assignment of the instance variable string
.
Is this a know issue and are there any workarounds?
Thanks :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要在 .m 实现文件中调用
@synthesize string
,而是编写自己的 getter。例如,
有关属性的更多信息(以及当您不执行@synthesize时该怎么做)可以在以下位置找到:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html
ps属性名称“string”可能会让任何人感到困惑其他人会在路上查看您的代码...我建议将其更改为更特定于程序
Don't call
@synthesize string
in your .m implementation file and instead write your own getter.e.g.
More information about properties (and what to do when you don't do
@synthesize
) can be found at:http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html
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