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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:30:27+00:00 2026-05-27T06:30:27+00:00

I have a CoreData entity with an NSNumber property (an Integer 16 in the

  • 0

I have a CoreData entity with an NSNumber property (an Integer 16 in the model). I have the following code:

NSLog(@"raw changeAmount=%d", changeAmount);

NSNumber *changeNumber = [NSNumber numberWithInt:changeAmount];

NSLog(@"number changeAmount=%d = %@", [changeNumber intValue], changeNumber);

record.changeAmount = changeNumber;

NSLog(@"new changeAmount=%d", [record.changeAmount intValue]);

changeAmount is an int with the value 123000 when I run my test. When I test on iOS 4, everything works properly and prints out 123000. However, if I run this same code on iOS 5, the value is something like -8072 or -25,536. Like so:

raw changeAmount=123000
number changeAmount=123000 = 123000
new changeAmount=-8072

What the heck happened between iOS4 and iOS5 that is causing this? Have I been setting my NSNumber properties incorrectly this entire time?

It doesn’t appear to be an integer size issue, because I changed the model to use integer 32 (which it should have been all along) and it’s still happening. So we aren’t getting integer overflow or anything.

  • 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-27T06:30:27+00:00Added an answer on May 27, 2026 at 6:30 am

    I have just run this code in CodeRunner

    size_t shortSize = sizeof(short);
    size_t intSize   = sizeof(int);
    
    short short123000 = 123000;
    int   int123000   = 123000;
    
    NSString *format = @"\nshortSize       => %d\n"
                       @"int Size          => %d\n"
                       @"short with 123000 => %d\n"
                       @"int with 123000   => %d";
    
    NSLog(format, shortSize, intSize, short123000, int123000);
    

    which results in:

    shortSize         => 2  
    int Size          => 4  
    short with 123000 => -8072  
    int with 123000   => 123000
    

    NB The size is in bytes and there are 8 bits in a byte thus 2*8 = 16bit and 4*8 = 32bit.

    I had similar issues with some of the apps I work on. It would appear that CoreData has become a bit stricter about enforcing its types. I was caught out by it to but I should have been more vigilant about what I was doing, if Apple had changed their API so that it did not behave as it is supposed to people would complain but when the API is changed to do what it advertised in the first place it’s just unfortunate and likely to catch people out.

    As you can see this is a simple integer overflow so if you know the range your working in you can easily fix this up.

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

Sidebar

Related Questions

On my Core Data Entity Book i have a boolean property, 'wasViewed' (NSNumber numberWithBool)
I have a simple Coredata model with one entity called conversation and the other
I have a Core Data entity which needs a gender property. I just need
I have an Core Data Entity with a number of attributes, which include amount(float),
In my core data model I have a Person entity that has a to
I have set up a Core Data model that includes an entity, Item with
I have an NSTreeController that manages an entity is a core data model and
In my Core Data managed object model, I have an entity Foo with a
I have 2 autogenerated entities : @interface ContactEntity : Entity @property (nonatomic, retain) NSString
I'm wanting to make a CoreData entity called Employees, some Employees could have a

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.