• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NDDictionary and int Values
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >NDDictionary and int Values (From: Roberto Sobachi <email@hidden>)

  • Prev by Date: NDDictionary and int Values
  • Next by Date: Re: NDDictionary and int Values
  • Previous by thread: NDDictionary and int Values
  • Next by thread: Re: NDDictionary and int Values
  • Index(es):
    • Date
    • Thread