Pure C function calling Objective-C method?

后端 未结 3 1060
囚心锁ツ
囚心锁ツ 2020-12-31 23:27

Okay, I\'ve read half a dozen threads on this subject, but none of the solutions appear to address exact needs.

Question:

How does a Pure C (.c) fun

3条回答
  •  不思量自难忘°
    2021-01-01 00:25

    I hope i understand you correctly!

    You can do this via callback-function.

    In you C file use this:

    Define the callback-type

    eventcallback g_callback;
    

    Implement callback-class (executed by objective-c code)

    void comm_set_callback(eventcallback callback){
       g_callback = callback;
    }
    

    in objective-c:

    Set the callback (i.e.: in viewDidLoad())

    comm_set_callback(&testfkt);
    

    C-Method called from extern C-function

    void testfkt(){
     [refToSelf testmethod];
    }
    

    Objective-C Method called from C-Method testfkt

    -(void)testmethod{
       ...
    }
    

提交回复
热议问题