@property与readonly组合复制有意义吗? [英] Does @property copy in combination with readonly make sense?
本文介绍了@property与readonly组合复制有意义吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我理解正确, copy
强制setter创建传入的对象的副本。但是,如果我与一起使用它readonly
,不会有一个setter。那么我的假设是正确的,结合 @property(copy,readonly)
没有任何意义,或者我错过了什么?
If I understand this correctly, copy
enforces the setter to create a copy of the object passed in. However, if I use it together with readonly
, there won't be a setter. So is my assumption correct, that combining @property (copy, readonly)
doesn't make any sense or am I missing something?
推荐答案
这确实有意义。例如,如果您只想在实现中访问属性的setter:
It does make sense. For instance, if you want to access a property's setter in your implementation only:
@interface MyClass : NSObject
@property (nonatomic, copy, readonly) NSData *data;
- (id)initWithData:(NSData *)data;
@end
以及<$ c $的课程续集c> .m file:
@interface MyClass ()
@property (nonatomic, copy, readwrite) NSData *data;
@end
请注意副本,只读$在这种情况下,需要公共标题中的c $ c>声明!
这篇关于@property与readonly组合复制有意义吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文