Objective-C passing methods as parameters

前端 未结 2 697
小蘑菇
小蘑菇 2021-02-11 18:04

How do you pass one method as a parameter to another method? I\'m doing this across classes.

Class A:

+ (void)theBigFunction:(?)func{
    // run the func         


        
2条回答
  •  清歌不尽
    2021-02-11 18:38

    Another option is to look at blocks. It allows you to pass a block of code (a closure) around.

    Here's a good write up on blocks:

    http://pragmaticstudio.com/blog/2010/7/28/ios4-blocks-1

    Here's the apple docs:

    http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/Blocks/Articles/00_Introduction.html

提交回复
热议问题