properties - Objective-C property name mapping -
i wonder if there easy , fast way map property name adopted protocol property comes base class?
suppose example:
@protocol proto <nsobject> @property (nonatomic, readonly, strong) nsstring *objectid; @end ... @interface mybase : nsobject @property (nonatomic, readonly, strong) nsstring *objectid; @end ... @interface myclass : mybase<proto> @end
in case guess don't need - property there getter , setter promise have them given when adopting protocol fulfilled. if property in mybase
called objid
, not objectid
? there language tricks using dynamic
, synthesize
, getter=
or other way make refer base class' property without manually defining getter/setter in myclass
, returning/setting base class' property?
rationale: want cover third party library protocol layer used ui can change provider similar 1 under hood (or provide simulator testing). protocols define replicate api of library, property names include naming don't want in interfaces.
objective-c offer hooks such -(id)forwardingtargetforselector:(sel)aselector
works ruby's method_missing
. can use redirect objective-c messages other objects and/or selectors. if have consistent different naming pattern in properties e.g. *objectid -> objid, use that. caveat using of stuff risky - if can accomplish same thing few overrides, instead. code less fragile, if isn't quite clean
Comments
Post a Comment