Re: More NSDictionary to CFDictionary
Re: More NSDictionary to CFDictionary
- Subject: Re: More NSDictionary to CFDictionary
- From: Matt Gough <email@hidden>
- Date: Fri, 17 Nov 2006 08:16:43 +0000
On 16 Nov 2006, at 23:31, Adam R. Maxwell wrote:
@implementation NSDictionary ( UWDictionaryAdditions )
-( BOOL )hasKey:( id )aKey;
{
return CFDictionaryContainsKey( self, aKey);
}
UWDictionaryAdditions.m:16: warning: passing argument 1 of
'CFDictionaryContainsKey' from incompatible pointer type
CFDictionaryContainsKey((CFDictionaryRef)self, aKey);
...but personally I would stick to the Cocoa side of the fence and do
the following unless you really find a performance issue...
return [[self objectForKey:aKey] != nil];
One thing to be careful of with CF functions is that many of them
don't accept nil as a parameter, and CFDictionaryContainsKey(self,
aKey) will crash if aKey is nil (at least for a dictionary
instantiated via NSDictionary methods) whereas objectForKey: will
just return nil. So you may also want to NSParameterAssert(aKey !=
nil) or return (nil == key ? NO : CFDictionaryContainsKey( self,
aKey)) if using CF directly.
But in his case, self cannot be nil as if it were hasKey wouldn't
even have been called. But in general, yes avoid passing nil to CF
routines.
Matt
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden