Need assistance understanding objective-c protocol -
#import <uikit/uikit.h> @protocol myprotocol <nsobject> -(void)amethod; @end @interface viewcontroller : uiviewcontroller @property (weak) id<myprotocol> dsource; @end
i trying firm grip on obj-c protocols, reading apple doc study, few things not clear me. below points doc:
the pie chart view class interface need property maintain track of info source object. (the code above, declare protocol way, when have protocol declared in class why need tracking object, or protocol can defined in independent class? , need tracking object?)
by specifying required protocol conformance on property, you’ll compiler warning if effort set property object doesn’t conform protocol.
if effort phone call respondstoselector: method on id conforming protocol it’s defined above, you’ll compiler error there’s no known instance method it. 1 time qualify id protocol, static type-checking comes back; you’ll error if seek phone call method isn’t defined in specified protocol. 1 way avoid compiler error set custom protocol adopt nsobject protocol.
i dont understand question correct, property requires property id conforms property, if seek set else compiler rightly complains this because respondstoselector: method on nsobject
protocol, can either have protocol extend nsobject
(standard), or declare property nsobject
objective-c protocols
No comments:
Post a Comment