objective c - overriding property attribute in class extension -


say have interface

// car.h @interface car  @property ( readonly) nsinteger rpm @end  

i want users of access readonly

in other areas private code , not exposed users want manipulate rpm

say

// enginefeedback.h @interface enginefeedback @property(nonatomic , weak ) car *thecar; @end  // enginefeedback.m  -(void) enginerpmreceived:(nsinteger) newrpm {      thecar.rpm = newrpm; } 

how can accomplish (where need writeable)

can define class extension overrides attributes

// car_internal.h @interface car () @property(readwrite) nsinteger rpm  @end  

to able use

    // enginefeedback.m      #import "car_internal.h"     -(void) enginerpmreceived:(nsinteger) newrpm     {          thecar.rpm = newrpm;     } 

is bad ? there better way achieve ?

using class extension override readonly property declaration fine. (in fact that's primary purpose of readonly attribute.) however, car class need provide implementation of setrpm: work @ runtime.

so given declarations provided, somewhere in car.m you'd need this:

- (void)setrpm:(nsinteger)newrpm {      _rpm = newrpm; } 

note class extension can declared in enginefeedback.m if prefer.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -