Re: Why are properties access through NSURLProtocol class method rather than NSURLRequest instance method?
Re: Why are properties access through NSURLProtocol class method rather than NSURLRequest instance method?
- Subject: Re: Why are properties access through NSURLProtocol class method rather than NSURLRequest instance method?
- From: Mike Abdullah <email@hidden>
- Date: Mon, 16 May 2011 10:45:30 +0100
On 16 May 2011, at 03:57, Larry Campbell wrote:
> Seems odd to me that setting and getting properties of an NSURLRequest involve an NSURLProtocol class method:
>
> +[NSURLProtocol setProperty:forKey:inRequest:]
>
> rather than what seems to me the much more straightforward:
>
> -[NSMutableURLRequest setProperty:forKey:]
>
> Is there a reason for this?
This facility is provided for people creating custom URL protocols. I think it's assumed that if you need custom request properties, you'll write something like:
@implementation NSURLRequest (MyProtocol)
- (NSString *)myFoo;
{
return [NSURLProtocol propertyForKey:@"myFoo" inRequest:self];
}
@end
@implementation NSMutableURLRequest (MyProtocol)
- (void)setMyFoo:(NSString *)foo
{
if (foo)
{
[NSURLProtocol setProperty:foo forKey:@"myFoo" inRequest:self];
}
else
{
[NSURLProtocol removePropertyForKey:@"myFoo" inRequest:self];
}
}
_______________________________________________
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