iljawascoding
iljawascoding

Reputation: 1110

Is there a Cocoa proxy class that spares me the "respondsToSelector:"-check ?

Are you aware of an existing Cocoa proxy or forwarder class, that spares me the respondsToSelector: check every time I want to invoke an optional method on some other object?

Instead of writing this:

if ([delegate respondsToSelector:@selector(treeController:canCreateGroupInParent:)])
{
    [delegate treeController:treeController canCreateGroupInParent:inGroup];
}

I'd like to write this:

[[delgate safeForwarder] treeController:treeController canCreateGroupInParent:inGroup];

The safeForwarder should capture the invocation and and redirect to it's target, if it implements to requested method.

Anybody aware of existing component that does that. Don't want to re-invent the wheel.

Thanks, Ilja

Upvotes: 2

Views: 144

Answers (1)

catlan
catlan

Reputation: 25246

Check out Peter Steinberger PSTDelegateProxy. Here the blog post about it.

Upvotes: 5

Related Questions