[英]How to make a readonly property to readwrite in iOS?
I have a scenario like this, 我有这样的情况
@interface ClassA:UIView
@property(readonly,strong)UIView *aView;
@end
I have another class 我有另一堂课
@interface ClassB:NSObject
@property(readonly)ClassA *aObj;
@end
How can I access the view properties in ClassA like setHidden etc....using ClassB property 我如何使用ClassB属性访问ClassA中的视图属性,如setHidden等。
eg: 例如:
In another class ClassC.m , 在另一个类ClassC.m中,
import ClassB.h
@implementation ClassC
//
ClassB *bObj;
bObj.aObj.aView.hidden = YES;
(Note :I do not want to modify/add anything in .m for ClassA and ClassB) (注意:我不想在.m中为ClassA和ClassB修改/添加任何内容)
I want to know if this can be achieved by writing any category methods for ClassA. 我想知道是否可以通过为ClassA编写任何类别方法来实现。
I understand you want to change the properties of the object, not the variable that is pointing to it. 我了解您要更改对象的属性,而不是指向它的变量。 Thus the title is misleading, and you can change the object already. 因此,标题具有误导性,您可以更改对象。 Nothing prevents you from calling methods on any object. 没有什么可以阻止您在任何对象上调用方法。 If you want object immutability in Objective-C you have to code it inside the object for it to work. 如果要在Objective-C中实现对象不变性,则必须在对象内部对其进行编码以使其起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.