I have a selector as a property in my framework, which is a property that the user can set.
Here’s the property: @property SEL didBeginBackupSelector;
So in my class I synthesize it and implement it like this:
if (self.didBeginBackupSelector != nil)
{
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:self.didBeginBackupSelector name:@"backupHasStarted" object:nil];
}
Then I compile the framework and implement it.
framework.didBeginBackupSelector = @selector(didBegin:);
But instead of calling the selector in my class, it tries to call didBegin: in the framework’s class.
What am I missing?
In your code snippet you reference
self, which is referring to your framework class, not the caller. Your technique also has another problem, which is that if the didBeginBackupSelector changes after you register for the notification, it will not behave as expected. I would recommend you do something like the following instead:In your .h:
In your .m:
This will work even if the didBeginBackupSelector and didBeginBackupTarget change after registration.