• 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 setObject:forKey:] problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [NSMutableDictionary setObject:forKey:] problem


  • Subject: Re: [NSMutableDictionary setObject:forKey:] problem
  • From: m <email@hidden>
  • Date: Wed, 19 Oct 2005 15:15:22 -0700


On Oct 19, 2005, at 2:49 PM, Joachim wrote:

2) Why does [iPhotoAlbumDict respondsToSelector:@selector (objectForKey)] always return false? ([iPhotoAlbumDict class] returns NSCFDictionary.)

if (true || [iPhotoAlbumDict respondsToSelector:@selector (objectForKey)]) {
// The second half of the above expression always returns false,
// even though iPhotoAlbumDict DOES respond to the message below

"@selector(objectForKey)" should be "@selector(objectForKey:)" (note the colon; this is a common error beginners make)





1) What's wrong with my code [below]? Why isn't the NSDictionary object added with the setObject:forKey: call?

    // Initialise albumDict ivar
    if (albumDict)
        [albumDict release];
    [albumDict initWithCapacity:[iPhotoAlbums count]];

You're not creating albumDict anywhere. So albumDict is probably nil.

3) Am I handling memory correctly in my code? No leaks etc? I'm still struggling to understand how Objective-C memory management works.

I haven't looked over your code carefully, but when you add an object to a dictionary (or any container), the dictionary (or container) retains it (increments the reference count by one). Since your object is created using alloc+init, its being created with its reference count already at 1. So you need either to release your object after adding it to your dictionary, or (what I usually do) autorelease it when creating it.




Finally, does NSDictionary read the whole file into memory in the initWithContentsOfFile: call or does it just scan the file later at the given entry levels I specify in my code? The AlbumData.xml file can get quite big, but I don't want to use NSXMLParser as it involves way too much code.

Dunno. I wouldn't worry about it until there's evidence that it's a problem (i.e. you might be prematurely optimizing).


_murat



_______________________________________________
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


  • Follow-Ups:
    • Re: [NSMutableDictionary setObject:forKey:] problem
      • From: Joachim <email@hidden>
References: 
 >[NSMutableDictionary setObject:forKey:] problem (From: Joachim <email@hidden>)

  • Prev by Date: Re: [NSMutableDictionary setObject:forKey:] problem
  • Next by Date: Re: NSAutoreleasePool dilemma
  • Previous by thread: Re: [NSMutableDictionary setObject:forKey:] problem
  • Next by thread: Re: [NSMutableDictionary setObject:forKey:] problem
  • Index(es):
    • Date
    • Thread