• 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 <-- setter method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableDictionary <-- setter method


  • Subject: Re: NSMutableDictionary <-- setter method
  • From: Nick Zitzmann <email@hidden>
  • Date: Wed, 28 Apr 2004 13:10:21 -0600

On Apr 28, 2004, at 11:53 AM, Frederick C. Lee wrote:

However, I don't see a 'copy' method available to this class; didn't
work.

If the object complies with the NSCopying protocol, then -copy will work. NSMutableDictionary complies with the protocol. However, using -copy to copy an NSMutableDictionary will make an immutable copy, so don't use that if "Cities" is supposed to be mutable. In that case, you'd use -mutableCopy instead, which is part of the NSMutableCopying protocol.

So I discovered this:

- (void) setCities: (NSMutableDictionary *) theCities {
[Cities setDictionary:theCities];
[theCities release]; ----- ?
}

Is this the correct approach? Should I release 'theCities'?

No, you should never do that. theCities could be in the autorelease pool, and if the method releases it, then your application will crash. Instead, you need to do something like this: (written in Mail)

- (void)setCities:(NSMutableDictionary *)theCities
{
if (Cities != theCities) // make sure these don't point to the same object
{
[Cities release]; // get rid of the existing object
Cities = [theCities retain]; // and hold onto the new one
}
}

Nick Zitzmann
<http://www.chronosnet.com/>
_______________________________________________
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: 
 >NSMutableDictionary <-- setter method (From: "Frederick C. Lee" <email@hidden>)

  • Prev by Date: Re: cocoa-dev digest, Vol 2 #4105 - 16 msgs
  • Next by Date: RE: NSMutableDictionary <-- setter method
  • Previous by thread: NSMutableDictionary <-- setter method
  • Next by thread: RE: NSMutableDictionary <-- setter method
  • Index(es):
    • Date
    • Thread