objective c - Should a BOOL ivar be a pointer to allow another class to set it? -


my class has bool property needs set class, trying use pointer. i'm declaring property this:

@interface someclass : superclass {     bool *_shared; } @property(nonatomic) bool *shared; 

is correct way this? i'd set , access value this:

*self.shared = yes; 

or proper way set retainable property?

no, not want send pointer instance variable other class can set instance variable. doing fragile , breaks encapsulation. awful design pattern.

it unnecessary.

if instance can "send pointer" instance b, instance can send reference instance b. there, instance b can [instancea setshared:yes];.

@interface b:uiviewcontroller @property(strong) *controllera; @end  @interface a:uiviewcontroller @property bool dogdoorenabled; @end  @implementation ... - (void) dosomething {      b *b = .... instance of b ...;      [b setcontrollera: self]; } @end  @implementation b ... - (void) dosomethingelse {     bool ischeeseonfire = ... calculate whether cheese burning ...;     [[self controllera] setdogdoorenabled: !ischeeseonfire]; } @end 

(watch out retain cycle -- if somehow retains b, directly or indirectly, (strong) reference b create retain cycle. call [b setcontrollera:nil] when want break cycle.)

now, if there reason why still think need send pointer internal state of b, please update question.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -