Make public api readonly but internally read / write?

How to do it:

@interface Foo : NSObject @property (readonly) int bar; @end ... @interface Foo() @property (nonatomic) int bar; @end @implementation Foo @synthesize bar = _bar; // stuff that does self.bar = 123; @end 

so some external class cannot call foo.bar = 123 .. but internal methods inside Foo can ...?

+4
source share
1 answer

Adding readwrite to nonatomic in the class extension should do this:

 @property (readwrite, nonatomic) int bar; 
+4
source

Source: https://habr.com/ru/post/1434108/


All Articles