Re: NSDictionary allocation
Re: NSDictionary allocation
- Subject: Re: NSDictionary allocation
- From: Jean-Olivier Lanctôt <email@hidden>
- Date: Mon, 14 May 2007 19:52:54 -0400
AFAIK subclassing NSDictionary is a bad idea because it's a class
cluster (much like NSArray/NSString, etc.)
Maybe you should try using a category instead
--O.
On 14 mai 07, at 19:44, Boyd Collier wrote:
I want to allocate an NSDictionary and initialize its contents with
arguments passed to it, and to do this within the initialization I
make use of an NSMutableDictionary. But I want the dictionary
that's returned from my initialization to be an NSDictionary rather
than the NSMutableDictionary.
@interface AlleleDictionary : NSDictionary {
}
- (id)initWithSpagediData:(SpagediData*)spagediDataObj locus:(int)
locus;
@end
@implementation AlleleDictionary
- (id)initWithSpagediData:(SpagediData*)spagediDataObj locus:(int)
locus {
if ((self = [super init])) {
NSMutableDictionary *theAlleleDict = [[NSMutableDictionary alloc]
initWithCapacity:[spagediDataObj numberOfIndividuals] ];
// code that puts stuff into theAlleleDict (not shown)
self = [[NSDictionary alloc] initWithDictionary:
(NSMutableDictionary*)theAlleleDict copyItems:YES];
[theAlleleDict release];
}
return self;
}
@end
Then the code that calls the above looks like this:
AlleleDictionary *myDict = [[AlleleDictionary alloc]
initWithSpagediData:sharedData locus:0];
Although this seems to work, my gut feeling is that I'm possibly
creating a memory leak. Any comments/suggestions would be much
appreciated.
Boyd_______________________________________________
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:
40gmail.com
This email sent to email@hidden
_______________________________________________
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