iphone - Using id <delegate> as a property or parameter to a function -
so i'm not sure how works. briefly looked @ coworker's c# (i'm not .net developer), , see lot of stuff gets passed methods class object conforms interface. in objective-c well?
for example, i'm messing around mapkit api , created own class conforms mkannotation protocol can have custom views , properties typical pin gets dropped on map. plan on using class created,
address : nsobject as opposed mkplacemark class when place pins on map. in other view controllers , model classes, do:
@property (nonatomic, strong) id <mkannotation> object; //1 or
@property (nonatomic, strong) address *object; //2 i started example 1, when needed of properties of address object, found myself having typecast object anyway seemed what's point, or i'm missing point? guess end question is, 1 or 2 better, , in scenarios? thanks.
i go option 3 this:
address : nsobject <mkannotation> then when implement class, implement methods required conform mkannotation protocol.
this way can have best of both worlds.
protocols similar interfaces in languages such c# or java. 1 of main differences ability require methods , have other methods optional. since objective-c such dynamic language, you'll see number of calls such [foo responsetoselector:@selector(someselector:)]. if -someselector: marked optional, need check see if receiver "responds" message. if marked required, however, compile throw warning if didn't implement method. take @ objective-c language reference more information
Comments
Post a Comment