Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You will need to provide the C callback function within the Objective-C class implementation file, and this will only work if the callback is able to use a <em>context</em> pointer of some sort.</p> <p>So imagine the C callback signature is like this:</p> <pre><code>void myCallback(void *context, int someOtherInfo); </code></pre> <p>Then within the Objective-C class implementation file you need to use that callback to trampoline back into your Objective-C class (using the <em>context</em> pointer as the instance of the class to invoke):</p> <pre><code>// Forward declaration of C callback function static void theCallbackFunction(void *context, int someOtherInfo); // Private Methods @interface MyClass () - (void)_callbackWithInfo:(int)someOtherInfo; @end @implementation MyClass - (void)methodToSetupCallback { // Call function to set the callback function, passing it a "context" setCallbackFunction(theCallbackFunction, self); ... } - (void)_callbackWithInfo:(int)someOtherInfo { NSLog(@"Some info: %d", someOtherInfo); } @end static void theCallbackFunction(void *context, int someOtherInfo) { MyClass *object = (MyClass *)context; [object _callbackWithInfo:someOtherInfo]; } </code></pre> <p>If your C callback function does not accept some sort of <em>context</em> info, then:</p> <ol> <li>It's broken and this should be fixed/reported as a bug.</li> <li>You will need to rely on storing a <em>pointer-to-self</em> at global, static, scope to be used by the C callback function. This will limit the number of instances of <code>MyClass</code> to one!</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload