May 202012

I just learned something…

Why is the first line better than the 2nd line?

@property (nonatomic, weak) NSObject<ExplanationDelegate> * delegate;
@property (nonatomic, weak) id <ExplanationDelegate> delegate;

It so you can write code like this!

    if([_delegate respondsToSelector:@selector(rightButtonAction:)]) {
        [_delegate rightButtonAction];

If you use id instead of NSObject then you can’t, it won’t compile, you get “No known instance method for selector ‘respondsToSelector:'” which can really have you scratching your head!