I a writing a generic class that may be used in different projects by link.
At some moment, I call a method on a listener given by the one that owns the object and kept by assign into the class.
But sometimes, that caller may disapear, so I want in that case to route the return message to the application delegate.
Here is how I do for the caller (the caller is the one that created and owns the instance of my class) :
if ([self.responseListener respondsToSelector:@selector(serverAnswered:error:)]) {
// some job to construct the return object
[self.responseListener performSelector:@selector(serverAnswered:error:) withObject:response withObject:nil];
}
How may I reference the app delegate class in place of responseListener when the caller has disapeared ?
I’m not sure what you mean with “caller” in “when the caller has disappeared”. Here’s how you can access the application delegate from anywhere, though.
If you need to call methods on it unique to your particular application’s delegate, you need to import it and cast.
Update:
To call your own library methods on any app delegate, use a protocol.
This will make your API clear as you specify what methods your library users need to implement, and is a good solution as it allows for compile time checks instead of relying on run time dynamic message sending.
You can also skip the protocol, and call methods on it directly.