I want to set up something like this in my environment.
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self
forKeyPath:[@"values." stringByAppendingString: @"MyPreference"]
options:NSKeyValueObservingOptionNew
context:NULL];
I’m doing this from a Smalltalk environment. The particular Smalltalk can actually drive the above thru the objective-c runtime features. The problem is the “self” there as the addObserver: argument. From Smalltalk, I can create an C function pointer that will act as a callback into Smalltalk. But it can’t offer it’s notion of what an Object is to the ObjectiveC environment.
So I’m trying to figure out how to trampoline from some sort of object with the appropriate API that causes the function pointer I create to be executed. I’ve looked at NSInvokation and friends, but none of those are used to wrap around a C function pointer. And I’m not sure they’d translate the addObserver:forKeyPath:options:context: to do the right thing.
Boiled down the question is, how do you use existing Cocoa objects to register a response to a Notification that is the execution of a C function pointer without compiling any new objc code.
You’ll need to create a glue class in Objective-C. You could do this:
If you need to pass arguments to the callback, you’ll need to add instance variables to hold the arguments, and pass them to the init method.
Then you use it like this: