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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:46:44+00:00 2026-05-22T17:46:44+00:00

When trying to store a double or an int in a dictionary I get

  • 0

When trying to store a double or an int in a dictionary I get an error

error: Semantic Issue: Sending ‘double’ to parameter of incompatible type ‘id’

I have the following code

[data setValue:longitude forKey:@"longitude"];

longitude is a double.

How should I store this? should I just create a pointer to an int or a double?

  • 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-22T17:46:45+00:00Added an answer on May 22, 2026 at 5:46 pm

    As the other posts have stated, you need to use an NSNumber to wrap your double value in an object. The reason for this is that all the Cocoa foundation collection classes are designed to work with objects rather than primitive values. As you suggested, with some work you could in fact pass a pointer to a double value (I think, if you managed to cast it as an id type pointer), but as soon as your method finished and the double went out of scope it would be released and your pointer would now be pointing to garbage. With an object, the collection (NSDictionary, in this case) will retain your object when it’s added and release it when it’s removed or the collection is dealloc‘ed, ensuring your value will survive until you don’t need it anymore.

    I would do it as follows:
    NSNumber *tempNumber = [[NSNumber alloc] initWithDouble:longitude];
    [data setValue:tempNumber forKey:@"longitude"];
    [tempNumber release];

    Which will leave your NSNumber object with only a +1 reference count (the dictionary retaining it) and no autoreleases

    The other suggested method of doing:
    [data setValue:[NSNumber numberWithDouble: longitude] forKey:@"longitude"];
    will also work fine but your object will end up with +1 reference count an an autorelease from the numberWithDouble method. When possible I try to avoid autoreleases, but the code is more concise. YMMV.

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

Sidebar

Related Questions

I'm trying to return a double from another object then store that into a
I'm trying to store an xml serialized object in a cookie, but i get
I'm trying to store data in the following fashion with a string as the
I'm trying to read some numbers (double) from a file and store them in
I'm trying to get the numerical (double) value from a byte array of 16
I'm trying to store a password in a file that I'd like to retrieve
I am trying to store an xml value in my app.config file. The app.config
I am trying to store more than 1 data item at a single index
I am trying to store a large amount of boolean information that is determined
I'm trying to store the names of some variables inside strings. For example: Dim

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.