Protocols and forwardingTargetForSelector:
Protocols and forwardingTargetForSelector:
- Subject: Protocols and forwardingTargetForSelector:
- From: "email@hidden" <email@hidden>
- Date: Tue, 25 Feb 2014 14:42:34 +0000
I have an NSString subclass as below.
If the subclass doesn’t respond to a given selector I want to forward the selector to another object.
What is the best way to declare the interfaces for DBManagedString and DBManagedObject?
Should I declare a DBManagedObject protocol in which all the methods are optional?
And what happens with synthesis for properties declared in protocols?
@interface DBManagedString : NSString
- (id)initWithMonoString:(MonoString *)monoString;
- (MonoString *)representedMonoString;
@end
@implementation DBManagedString
- (id)forwardingTargetForSelector:(SEL)aSelector
{
#pragma unused(aSelector)
if (!self.forwardingTarget) {
self.forwardingTarget = [DBManagedObject objectWithMonoObject:(MonoObject *)self.representedMonoString];
}
return self.forwardingTarget;
}
@end
Jonathan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden