为什么Objective C中没有“mutablecopy”限定符? [英] Why there's no 'mutablecopy' qualifier in Objective C?

查看:136
本文介绍了为什么Objective C中没有“mutablecopy”限定符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:


请原谅我可怜的英语:)



在Objective C中,'copy'限定符不保留可变性。我们必须创建一个属性strong或自己提供一个setter。



我只想知道为什么不提供mutablecopy限定符。任何具体原因或设计折衷?


解决方案


因为做一个可变的副本实际上有深刻和微妙的意义,使它不重要。



此外,如果属性支持可变复制,那么,将需要一个版本的setter和一个为getter,因为每个都有一个非常不同的潜在角色(如果你真的想要一个mutable属性,你可能需要一个可变的复制设置器和正常的保留getter。 )。



这些都没有解决深层和浅层可变拷贝的问题。


Possible Duplicate:
What's the best way to use Obj-C 2.0 Properties with mutable objects, such as NSMutableArray?

Please excuse my poor English :)

In Objective C, the 'copy' qualifier doesn't retain the mutability. We have to make a property 'strong' or provide a setter ourselves.

I just want to know why the 'mutablecopy' qualifier is not provided. Any specific reason or design tradeoffs ?

解决方案

Why no 'mutablecopy'?

Because making a mutable copy actually has deep and subtle meaning that makes it nontrivial. As well, you pretty much never want an objects internal storage to be externally mutable.

Also, if properties were to support mutable copy, there would need to be a version for the setter and one for the getter as each has a very different potential role (if you really did want a mutable property, you might want a mutable copying setter and normal retain getter. Or the other way around.).

None of this addresses the even nastier issue of deep versus shallow mutable copy.

这篇关于为什么Objective C中没有“mutablecopy”限定符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆