简体   繁体   English

如何在iOS中将readonly属性设为可读写?

[英]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.

相关问题 如何在头文件(.h)中创建一个不可变的readonly属性,一个实现的可变读写属性(.m) - How to make an immutable readonly property in the header file (.h), a mutable readwrite property in implementaion (.m) 如何在Objective-C中将readonly属性转换为readwrite属性? - How to turn a readonly property into readwrite property in Objective-C? readonly public,readwrite private property - readonly public, readwrite private property Swift只读外部,读写内部属性 - Swift readonly external, readwrite internal property Quirk包含核心数据,协议和readwrite与readonly属性声明 - Quirk with Core Data, protocols, and readwrite vs. readonly property declarations 不允许分配'readonly'返回结果,但声明属性为“readwrite” - Assigning to 'readonly' return result not allowed, but property is declared “readwrite” 继承属性时,在readon从readonly读取继承属性时未设置合并器 - Inheriting properties, setter not synthetized when readwrite in inherited property from readonly 从API类中使读写变量成为只读变量 - Make readwrite variables from an API class which variables are readonly 读写和只读互斥 - readwrite and readonly mutually exclusive Objective C类扩展-如何使用readwrite方法覆盖readonly? - Objective C class extensions- how to overwrite readonly with readwrite method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM