Call an Objective-C Method from Swift app

前端 未结 1 1631
刺人心
刺人心 2021-01-29 14:57

I am making a Mac app, entirely in Swift. Now, I need to add an Objective-C function to the app, but I can\'t figure out how. I have very little knowledge about Objective-C, but

1条回答
  •  深忆病人
    2021-01-29 15:40

    Here's the solution for an iOS app:

    File Thing.h:

    #import 
    
    @interface Thing : NSObject
    
    void MyCreatePDFFile (CGRect pageRect, const char *filename);
    
    @end
    

    File Thing.m:

    #import "Thing.h"
    
    @implementation Thing
    
    void MyCreatePDFFile (CGRect pageRect, const char *filename) {
        // ... your code here ...
    }
    
    @end
    

    In the bridging header:

    #import "Thing.h"
    

    Now your Swift code can see and call this function.

    0 讨论(0)
提交回复
热议问题