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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:49:48+00:00 2026-05-25T02:49:48+00:00

I have a need to map char values to int values in Objective-C. I

  • 0

I have a need to map char values to int values in Objective-C. I know NSDictionary is out because it deals with reference types, and these are values. The map will be used while iterating through an NSString. Each character in the string will be converted to an integer value. All the integers will be summed together.

Using NSDictionary seems like a bad fit because of all the type coercion I’d have to do. (Converting values types, char and int, to reference types.)

I figure I’ll have to drop down to C to do this, but my experience with C libraries is very limited.

Is there something most C developers use that will map char values to int values?

Edit for clarification

The C# equivalent would be a Dictionary<char,int>.

In pseudocode, I’d like to the following:

for (int i = 0; i < [string length]; i++) {
    char current = [string characterAtIndex:i];
    int score = map[current]; // <- I want map without boxing 
    // do something with score
}
  • 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-25T02:49:49+00:00Added an answer on May 25, 2026 at 2:49 am

    If I understand correctly, you want to store chars and ints in a dictionary, as keys and values. However, NSDictionary only accepts objects. The solution? Wrap the chars and ints in the NSNumber object:

    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                          [NSNumber numberWithInt:1],
                          [NSNumber numberWithChar:'a'],
                          [NSNumber numberWithInt:2],
                          [NSNumber numberWithChar:'b'], 
                          nil];
    

    Or if you don’t want boxing, why not just make a function that takes chars and returns ints?

    int charToScore(char character)
    {
        switch (character) {
            case 'a':
                return 1;
            case 'b':
                return 2;
            default:
                return 0;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple requirement, i need a map of type . however i
I have a number, say 123456, and I need to map it to a
We have a project using FluentNibernate to map the entities. Now I need to
I have a map of a vector of char 's and a vector of
I need a Map<Integer,String> with a major need to do fast retrievals of values
I have an array of strings which need to be taken into a map.
I have two tables in a legacy database that I need to map using
I have a class that I need to map that looks a bit like
I have need to map PriorityId -> TcTaskPriorityId Mapper.Configuration.RecognizePrefixes(TcTask); Mapper.CreateMap<Task, TpTasksEntity>(); Task t =
for my application, i need to use a hash map, so i have written

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.