Calling C function in Objective-C Awake from Nib

后端 未结 1 924
面向向阳花
面向向阳花 2021-01-24 10:53

I had to implement a C function in an Objective-C class that normally would get called with int main (in it\'s own file). Since I\'m unfamiliar with splicing code I

相关标签:
1条回答
  • 2021-01-24 11:33

    It's called just the same as you would from C and you can call any C function you like:

    // Cocoa Imports
    
    #import "AppDelegate.h"
    ...
    
    // C Inlcudes
    #include <stdio.h> 
    
    // (int main had to change to something else obviously)
    
    int dos (const char *filename)
    { 
        printf ("I was passed '%s'\n", filename); 
    }
    
    // (back to cocoa)
    
    @implementation AppDelegate
    
    @synthesize window;
    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
        dos("/path/to/some/file");
    }
    
    0 讨论(0)
提交回复
热议问题