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 8826237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:05:18+00:00 2026-06-14T07:05:18+00:00

In a program I am working on I am using a C array of

  • 0

In a program I am working on I am using a C array of chars (it is potentially a very large array, so I do not want to use an NSArray). Each one is storing a value that corresponds to a particular status.

So that I can store some information about each status, I am using an NSDictionary. Each of the keys correspond to the possible status values. For each key, the value is a sub-dictionary that contains information I need corresponding to the status value.

Currently I am doing the following whenever I want to extract information from the NSDictionary:

for(i=0; i<arrayLen; i++) {

NSString *lookupKey1 = [[NSString alloc]initWithFormat:@"%i", array[i]];
int stateInfo1 = [[[statesDict objectForKey:lookupKey1] 
                                objectForKey:@"infoKey1"] intValue];
[lookupKey1 release];


NSString *lookupKey2 = [[NSString alloc]initWithFormat:@"%i", array[i]];
int stateInfo2 = [[[statesDict objectForKey:lookupKey2] 
                                objectForKey:@"infoKey2"] intValue];
[lookupKey2 release];


// Now do something with the values just obtained...

}

This works just fine, but what I don’t like about having to do this is that I am having to allocate an NSString, just to look up a key. It feels like I am performing unnecessary operations. This is a particular concern to me since I am iterating through a large array and I don’t want to be slowing it down by doing it in this way unless I absolutely have to.

When I try to simply pass the char in as I originally hoped I could to:

char stateInfo = [[[statesDict objectForKey:array[i]] 
                                objectForKey:@"infoKey"] charValue];

The compiler gives the warning “Passing argument 1 of objectForKey: makes pointer from integer without a cast”, and the debugger throws an EXC_BAD_ACCESS exception.

I have also tried passing in a formatted string literal:

char stateInfo = [[[statesDict objectForKey:(@"%i", array[i])] 
                                objectForKey:@"infoKey"] charValue];

This throws up exactly the same error. Does anybody know if there is a more efficient way to do what I am trying to do, or is the way I described in the first snippet the ‘correct’ way to go about what I am trying to do?

  • 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-14T07:05:20+00:00Added an answer on June 14, 2026 at 7:05 am

    have you tried

    char stateInfo = [[[statesDict objectForKey:[NSString stringWithFormat:@"%i", array[i]] 
                                    objectForKey:@"infoKey"] charValue];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a large number adding program (without using biginteger class). I
I am using Junit 4. My whole program is working fine. I am trying
Im working on a program to send and recieve SMS using a GSM modem
i am working on a program in Python and using Pygame. this is what
I am working on a program in C and using the SDCC compiler for
I'm working on a program that accesses StarTeam using the StarTeam SDK for .NET.
I'm working on a little program to make my life easier when using Microsoft
I'm working on a voice-controlled program for iOS and using Pocketsphinx as my recognition
I was working on a program in Netbeans on Linux using a gcc compiler
I am working on a program base on C++ and also using SiliconSoftware interface.

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.