Explanation of Cocoa @selector usage

前端 未结 6 2054
轮回少年
轮回少年 2021-01-30 14:50

I\'m new to Cocoa/Cocoa Touch, and working through a development book. I\'ve come across situations where the @selector() operator is used. I\'m a bit lost on how and when the

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 15:17

    One practical example is validateMenuItem method where menu items are identified with their target actions.

    Simplified example:

    - (BOOL)validateMenuItem:(NSMenuItem *)item {
        if ([item action] == @selector(selectFiles:) && otherCondition) {
            return YES;
        } else {
            return NO;
        }
    }
    

提交回复
热议问题