user187676
user187676

Reputation:

C-callback without class pointer

In my app I use the JavaScriptCore API to install a JS function in the WebView context with a C callback in my Cocoa class. Now there is no way I can pass that callback a userData/refcon pointer to know what class the callback belongs to.

Is there a way to resolve this without passing a pointer? Globals don't seem to work since they get overwritten by other class instances.

Upvotes: 1

Views: 222

Answers (1)

bbum
bbum

Reputation: 162722

If a global won't work (because of multiple / concurrent calls, most likely), then you need some kind of context info.

If the API returns any kind of a unique identifier -- session #, an allocated struct, anything -- you could set up an NSMapTable that maps between that identifier and whatever Objective-C goop you might need.

Upvotes: 1

Related Questions