Re: NDDictionary and int Values
Re: NDDictionary and int Values
- Subject: Re: NDDictionary and int Values
- From: mmalcolm crawford <email@hidden>
- Date: Sat, 7 Feb 2004 01:23:00 -0800
On Feb 7, 2004, at 12:45 AM, Roberto Sobachi wrote:
I've got this NSDictionary, but it returns passing arg 1 from
incompatible pointer type:
int i=0;
NSNumber *idcomic;
for(i=0; i<1000; i++) {
idcomic = [[NSNumber alloc] initWithInt: i];
demoDict = [[NSDictionary alloc] init];
demoDict = [NSDictionary dictionaryWithObjectsAndKeys: (id *)
idcomic, @"idcomic", @"Wolverine", @"protagonist", @"Senza Artigli",
... }
Umm, so the type you're defining in the first parameter is wrong.
Why are you casting to (id *)?
You should also note that, as presented, the code is leaking memory.
This line:
demoDict = [[NSDictionary alloc] init];
simply creates and then, given the reassignment on the next line, leaks
a new dictionary.
Your code is therefore creating 2000 dictionaries, leaking 1000 of
those, and losing the reference to all but the last one. You're also
leaking 1000 NSNumber objects.
May I suggest you review the basic documentation for Objective-C
<
http://developer.apple.com/documentation/Cocoa/Conceptual/
CocoaObjects/index.html>, and the memory management discussion and
articles referenced at <
http://www.alastairs-place.net/cocoa/faq.txt>.
mmalc
_______________________________________________
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.