• 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: Jörn Salewski <email@hidden>
  • Date: Sat, 07 Feb 2004 10:49:11 +0100

Dear Roberto,

> I've got this NSDictionary, but it returns passing arg 1 from
> incompatible pointer type:
>

The problem is with your casting "(id *) idcomic,"

1. The Objective-C type id is allready a pointer.
If you declare idcomic as

NSNumber *idcomic;

You could have equally well declared it with

id idcomic;

Note the omission of the * here. So, if you really want to cast your idcomic
pointer, do it this way "(id)idcomic,"

2. But, a cast is actually completely unnecessary. Just leave it out.

> 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",
> @"title", @"12", @"prognumber", @"fdsf", @"sernumber", @"fdsf",
> @"story", @"fdsf", @"pencils", @"fdsf", @"inks", @"fdsf", @"colors",
> @"fdsf", @"vote", @"fdsf", @"series", @"fdsf", @"publisher", @"fdsf",
> @"number", @"fdsf", @"pages", @"fdsf", @"date", @"fdsf", @"price",
> @"fdsf", @"value", @"fdsf", @"covertype", @"sdfdsf", @"note", nil];
>
> }
>

Actually this is not the only problem with your code.

The variables idcomic and demoDict are NOT your objects, they are pointers
to objects.

> demoDict = [[NSDictionary alloc] init];

demoDict now points to an immutable instance of NSDictionary. You explicitly
have allocated memory for this instance (alloc). Therefore you are
responsible to free ([demoDict release];) this memory sometime later in your
programm when you don't need it anymore.

> demoDict = [NSDictionary dictionaryWithObjectsAndKeys:...

Now demoDict points to some other instance of an NSDictionary. You don't
have a reference to the previously allocated NSDictonary anymore and you
won't be able to release it. You'll leak memory. You do this a thousand
times in your loop.

The same happens with your idcomic pointer to your NSNumber instance. With
the difference that you loos your reference in the next iteration through
your loop.

Roberto, I don't want to be offensive, but I'd strongly suggest that you
again read the documentation about memory mangement.
Maybe it would also be a good idea to work carefully through a beginners
tutorial, or even to buy a sort of beginners book.


Yours,

Joern Salewski
_______________________________________________
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: Re: NDDictionary and int Values
  • Next by Date: are there any custom IB Palettes?
  • Previous by thread: Re: NDDictionary and int Values
  • Next by thread: are there any custom IB Palettes?
  • Index(es):
    • Date
    • Thread