• 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: NSMutableDictionary initialization problems
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableDictionary initialization problems


  • Subject: Re: NSMutableDictionary initialization problems
  • From: Jacob Lukas <email@hidden>
  • Date: Sun, 17 Oct 2004 23:09:48 -0700

On Oct 17, 2004, at 12:13 PM, Jacob Lukas wrote:

I have a subclass of NSDocumentController. In this subclass, I maintain a mutable array. Unfortunately, I cannot find a way to initialize it.

I tried the following methods in -init:
_myArray = [NSMutableDictionary dictionary];
-> _myArray is an NSCFString
_myArray = [NSMutableDictionary dictionaryWithDictionary:[NSDictionary dictionary]];
-> _myArray is a CFDictionary
_myArray = [[NSDictionary dictionary] mutableCopy];
-> _myArray is a CFDictionary

I tried initializing _myArray just before I use it:
if (!_myArray)
_myArray = [NSMutableDictionary dictionary];
[_myArray addObject:someObject];

A dictionary is not the same thing as an array, you can't just do 'addObject' on a dictionary -- that's an NSMutableArray message.

Do this:

_myArray = [[NSMutableArray alloc] init];

Also, note that when you do something like this:

[NSMutableDictionary dictionary];
[NSMutableDictionary dictionaryWithDictionary:[NSDictionary dictionary]];

... you're getting back an autoreleased object, which is probably not what you want. If you don't see "alloc", "retain" or "copy" anywhere, the object isn't retained and it will crash if you try to come back and use it later.

...Somehow I knew it was just me being stupid....

But that wasn't the only problem. I also stopped formatting a second drive, which messed up the system a bit, but I fixed it by running the Disk Utility on the install CD.

Thanks for all the help *bangs head on wall*

Jacob

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
References: 
 >NSMutableDictionary initialization problems (From: Jacob Lukas <email@hidden>)
 >Re: NSMutableDictionary initialization problems (From: Scott Stevenson <email@hidden>)

  • Prev by Date: Hot (well, thread-safe) or not?
  • Next by Date: Re: Hot (well, thread-safe) or not?
  • Previous by thread: Re: NSMutableDictionary initialization problems
  • Next by thread: turn off warnings for proxies
  • Index(es):
    • Date
    • Thread