Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3304566
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:04:32+00:00 2026-05-17T21:04:32+00:00

I’m writing a game using cocos2d-iphone and our stages are defined in .plist files.

  • 0

I’m writing a game using cocos2d-iphone and our stages are defined in .plist files. However, the files are growing large – so I’ve developed an editor that adds some structure to the process and breaks most of the plist down into fixed fields. However, some elements still require plist editor type functionality, so I have implemented an NSOutlineView on the panels that show ‘other parameters’. I am attempting to duplicate the functionality from XCode’s ‘Property List Editor’.

I’ve implemented the following system; http://www.stupendous.net/archives/2009/01/11/nsoutlineview-example/

This is very close to what I need, but there is a problem that I’ve spent most of today attempting to solve. Values for the key column are calculated ‘backwards’ from the selected item by finding the parent dictionary and using;

return [[parentObject allKeysForObject:item] objectAtIndex:0];

However, when there are multiple items with the same value within a given dictionary in the tree, this statement always returns the first item that has that value (it appears to compare the strings using isEqualToString: or hash values). This leads to the key column showing ‘item1, item1, item1’ instead of item1, item2, item3 (where items 1-3 all have value ”). I next tried;

-(NSString*)keyFromDictionary:(NSDictionary*)dict forItem:(id)item
{
for( uint i = 0; i < [[dict allKeys] count]; i++ ) {
    id object = [dict objectForKey:[[dict allKeys] objectAtIndex:i]];

    if ( &object == &item ) {
        return [[dict allKeys] objectAtIndex:i];
    }
}   

return nil;
}

But this always returns nil. I was hoping that somebody with a bit more experience with NSOutlineView might be able to provide a better solution. While this problem only appears once in the linked example, I’ve had to use this a number of times when deleting items from dictionaries for instance. Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:04:33+00:00Added an answer on May 17, 2026 at 9:04 pm
    return [[parentObject allKeysForObject:item] objectAtIndex:0];
    

    However, when there are multiple items with the same value within a given dictionary in the tree, this statement always returns the first item that has that value …

    Well, yeah. That’s what you told it to do: “Get me all the keys for this value; get me the first item in the array; return that”.

    … this statement always returns the first item that has that value (it appears to compare the strings using isEqualToString: or hash values).

    It’s not that statement that’s doing it; it’s how dictionaries work: Each key can only be in the dictionary once and can only have exactly one object as its value, and this is enforced using the hash of the key and by sending the keys isEqual: messages (not the NSString-specific isEqualToString:—keys are not required to be strings*).

    The values, on the other hand, are not uniquified. Any number of keys can have the same value. That’s why going from values to keys—and especially to a key—is so problematic.

    *Not in NSDictionary, anyway. When you attempt to generate the plist output, it will barf if the dictionary contains any non-string keys.

    I next tried;

    -(NSString*)keyFromDictionary:(NSDictionary*)dict forItem:(id)item
    {
        for( uint i = 0; i < [[dict allKeys] count]; i++ ) {
            id object = [dict objectForKey:[[dict allKeys] objectAtIndex:i]];
    
            if ( &object == &item ) {
                return [[dict allKeys] objectAtIndex:i];
            }
        }   
    
        return nil;
    }
    

    But this always returns nil.

    That’s the least of that code’s problems.

    First, when iterating on an NSArray, you generally should not use indexes unless you absolutely need to. It’s much cleaner to use fast enumeration.

    Second, when you do need indexes into an NSArray, the correct type is NSUInteger. Don’t mix and match types when you can help it.

    Third, I don’t know what you meant to do with the address-of operator there, but what you actually did was take the address of those two variables. Thus, you compared whether the local variable object is the same variable as the argument variable item. Since they’re not the same variable, that test always returns false, which is why you never return an object—the only other exit point returns nil, so that’s what always happens.

    The problem with this code and the earlier one-liner is that you’re attempting to go from a value to a single key, which is contrary to how dictionaries work: Only the keys are unique; any number of keys can have the same value.

    You need to use something else as the items. Using the keys as the items would be one way; making a model object to represent each row would be another.

    If you go the model-object route, don’t forget to prevent multiple rows in the same virtual dictionary from having the same key. An NSMutableSet plus implementing hash and isEqual: would help with that.

    You probably should also make the same change to your handling of arrays.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm making a simple page using Google Maps API 3. My first. One marker
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.