Re: Subclass of NSMutableDictionary hanging
Re: Subclass of NSMutableDictionary hanging
- Subject: Re: Subclass of NSMutableDictionary hanging
- From: Ali Ozer <email@hidden>
- Date: Fri, 2 Mar 2007 23:32:52 -0800
It's probably raising an exception --- check the console. From the UI
point of view it might feel like a hang, but as you point out, the app
is still alive.
You're getting an exception because you're subclassing
NSMutableDictionary, which is abstract. If you really want to
subclass, you need to implement at least the primitive methods, which
are declared in the base classes in NSDictionary.h:
- (NSUInteger)count;
- (NSEnumerator *)keyEnumerator;
- (id)objectForKey:(id)aKey;
- (void)removeObjectForKey:(id)aKey;
- (void)setObject:(id)anObject forKey:(id)aKey;
See http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_9.html
.
If all you want are a custom init method and custom get and set
methods, you can get away without a subclass, by using a category.
Ali
On Mar 2, 2007, at 10:31 , Nick Forge wrote:
I am developing a preferencePane that makes use of a subclass of
NSMutableDictionary. My subclass (SPPowerSourceSettings) has only
three methods, which is one custom init method and a pair of "get
and set" methods. Here is the code for my custom init method:
- (SPPowerSourceSettings *) initWithSettings:(NSDictionary *)settings
sourceName:(NSString *)sourceName
{
self = [super init];
if (self != nil) {
NSDictionary *sourceSettings;
sourceSettings = [[settings objectForKey:@"Custom Profile"]
objectForKey:sourceName];
[self setDictionary:sourceSettings];
}
return self;
}
Basically what is happening is - when an instance of this class is
created, System Preferences.app (the host app) hangs. If I comment
out the "[self setDictionary:sourceSettings];" line, then it doesn't
hang. I have narrowed it down through extensive testing to the fact
that if I try and add an object (or an entire dictionary) to the
SPPowerSourceSettings instance then preferencePane hangs instantly.
I am able to press "Show All" in System Preferences.app, so it
doesn't really crash as such, it just hangs there.
My instances of SPPowerSourceSettings are called acSettings,
batterySettings and upsSettings. Is there some naming convention
when it comes to preferencePanes that could be causing a naming
conflict? Is there any other conventions that I should've followed?
I have already named all of my own classes as SPxxxx to avoid class
name conflicts....
Thanks in advance,
Nick
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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