How to create global functions in Objective-C

前端 未结 5 1651
攒了一身酷
攒了一身酷 2020-11-30 02:03

I\'m developing an iphone app and I need to have some functions to use globally in my classes.

But how can I do this?

I just tried to create functions.

5条回答
  •  暖寄归人
    2020-11-30 02:25

    When you want a global function, just write a regular C function. The Objective-C syntax is meant to be used solely in the context of object methods.

    void printTest() {
        NSLog(@"This is a test");
    }
    

    You also have to add the declaration in the functions.h header:

    void printTest();
    

提交回复
热议问题