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

  • SEARCH
  • Home
  • 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 8763697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:50:35+00:00 2026-06-13T15:50:35+00:00

I’m having a strange problem while using NSDictionnary … I’m trying to retrieve an

  • 0

I’m having a strange problem while using NSDictionnary …

I’m trying to retrieve an object for a key that is present is the dictionnary with the method objectForKey, but it returns nil instead.

When I print out the whole dictionnary, I can see clearly the key and the value I’m looking for.

Here is the code :

- (MObject *)GetWithMProperty:(MProperty *)prop {
    NSLog(@"We search an object for a property named %@", prop.Name);
    NSArray *keyArray =  [_dict allKeys];
    int count = [keyArray count];
    for (int i=0; i < count; i++) {
        MObject *tmp = [_dict objectForKey:[ keyArray objectAtIndex:i]];
        NSLog(@"Key = %@ | Object = %d", ((MProperty*)[keyArray objectAtIndex:i]).Name, tmp.GetTypeId);
        if (prop == [keyArray objectAtIndex:i])
            NSLog(@"Wouhou !");
        else
            NSLog(@"Too bad :(");
    }
    return [_dict objectForKey:prop];
}

And the stack trace :

2012-10-29 11:24:07.730 IOS6[1451:11303] We search an object for a property named Value
2012-10-29 11:24:07.730 IOS6[1451:11303] Key = Name | Object = 4
2012-10-29 11:24:07.731 IOS6[1451:11303] Too bad :(
2012-10-29 11:24:07.731 IOS6[1451:11303] Key = Value | Object = 0
2012-10-29 11:24:07.732 IOS6[1451:11303] Too bad :(

It’s a bit complicated, I’m using J2ObjC to compile a fully functional Engine, and thus I can’t modify the classes MProperty and MObject (used by the Engine).

MProperty doesn’t conforms to NSCopying protocol, so I created a classe called IPhoneMProperty that inherits from MProperty and conforms to the protocol.

Here is this class :

@implementation IPhoneMProperty

- (id)initWithMProperty:(MProperty *)prop {
    self = [super initWithInt:prop.OwnerTypeId withNSString:prop.Name withInt:prop.TypeId withMBasicValue:prop.DefaultValue withInt:prop.Flags];
    return self;
}

- (id)copyWithZone:(NSZone *)zone {
    IPhoneMProperty *prop = [[IPhoneMProperty alloc] initWithMProperty:self];
    return prop;
}

@end

And the method I use to add object and keys to the dictionnary :

- (void)SetWithMProperty:(MProperty *)prop withMObject:(MObject *)obj {
    IPhoneMProperty *tempKey = [[IPhoneMProperty alloc] initWithMProperty:prop];
    [_dict setObject:obj forKey:tempKey];
}

I hope it’s clear enough, actually it’s the only solution I found for the moment, but it doesn’t work 🙁

Can anyone helps me with this ?

Thanks !

  • 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-06-13T15:50:36+00:00Added an answer on June 13, 2026 at 3:50 pm

    The problem exists in the line

        if (prop == [keyArray objectAtIndex:i])
    

    Instead, implement isEquals: method in your MProperty class.

    -(BOOL)isEquals:(MProperty*)inProp {
      if( [inProp.name isEqualToString:self.name] )return YES;
    
      return NO;
    }
    

    And, here, instead of the line

        if (prop == [keyArray objectAtIndex:i])
    

    use the following line,

        if ([prop isEquals [keyArray objectAtIndex:i]])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

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
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace

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.