Can I inline static class methods in Objective-C?

后端 未结 3 1276
情深已故
情深已故 2021-01-13 05:50

You can declare functions as inlines like this:

#ifdef DEBUG
void DPrintf(NSString *fmt,...);
#else
inline void DPrintf(NSString *fmt,...) {}
#endif
<         


        
3条回答
  •  星月不相逢
    2021-01-13 06:04

    Yes!

    You can accomplish this with blocks

    -(void)viewDidLoad {
    
        void(^inlineFunction)(int) = ^(int argument) {
            NSLog(@"%i", argument);
        };
            
        inlineFunction(5);//logs '5'
    
    }
    

    Apple even documents this here (archive) so it's not a private method as many online seem to believe.

    Enjoy!

提交回复
热议问题