objective c - Accessing object property by assignment -
say have class below
@interface restaurant : nsobject @property (nonatomic,strong) nsstring *restaurantid; @property (nonatomic,strong) nsstring *restaurantname; @property (nonatomic,strong) nsstring *restaurantaddress; @end
if creating "restaurant" object "rest" , and can access properties rest.restaurantid , on.
my question is, how can access properties if assigning objects.something this
restaurant *rest = [[restaurant alloc]init]; [rest setrestaurantname:@"mcd"]; id proxyobject; proxyobject = rest;
how can access property "restaurantname" using proxyobject instead of rest?
thank you
by using id dynamic type, cannot access property dotsyntax, can use automaticly generated accessors methods. if have @property called var, can use getter
- (id) var;
and setter
- setvar:(id)var;
meaning in case can code like
[proxyobject setrestaurantid:@"anid"] // setter nsstring * restid = [proxyobject restaurantid]; //getter
and on each @property.
(look how getter name of property , how setter name starts set , name of property starting capital letter)
Comments
Post a Comment