Re: Determining if NS/CFDictionary is mutable?
Re: Determining if NS/CFDictionary is mutable?
- Subject: Re: Determining if NS/CFDictionary is mutable?
- From: Tomas Zahradnicky <email@hidden>
- Date: Mon, 23 Dec 2002 21:54:15 +0100
Hi,
Is there any public, documented way I can figure out whether a
NSDictionary is a mutable dictionary? This doesn't work:
- (NSMutableDictionary *)asMutableDictionary;
{
if ([self isKindOfClass: [NSMutableDictionary class]]) return
(NSMutableDictionary *)self;
return [[self mutableCopy] autorelease];
}
Without being able to do this, I end up creating lots of autoreleased
dictionaries because my API takes a NSDictionary and outputs a
NSDictionary. 99% of the time it will be mutable, so I'd like to save
the object creation overhead where I can.
All the dictionaries I've found are NSCFDictionaries, but
NSCFDictionary is a subclass of NSMutableDictionary even when the
dictionary is not mutable. I've checked in the CFLite sources and it
appears what I want is __CFDictionaryGetType, but that of course is
not public.
Hello Nick,
you can use this to tell whether the dictionary is mutable or not.
However this function comes from CoreFoundation.framework and is not
in headers. It works, but use it at your own risk:
extern Boolean _CFDictionaryIsMutable(CFDictionaryRef ref);
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSDictionary *dic = [[NSDictionary alloc] init];
NSMutableDictionary *mdic = [[NSMutableDictionary alloc] init];
BOOL m = 0;
m = _CFDictionaryIsMutable( (CFDictionaryRef)dic );
m = _CFDictionaryIsMutable( (CFDictionaryRef)mdic );
[pool release];
return 0;
}
-Tomas
--
# Tomas Zahradnicky, Jr
# The Czech Technical University
# Dept of Computer Science, FEE-CTU Prague
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.