wholly_cow
wholly_cow

Reputation: 977

NSNumber assignment issues. Wrong number being assigned

I'm receiving data in JSON from an API and after converting the data into custom class I'm attempting to write certain properties into a core-data db.

My code is:

NSLog(@"topPost: %@; post(in): %@", topPostsEntity.totalAgainst,post.totalAgainst);
topPostsEntity.totalAgainst = post.totalAgainst;
NSLog(@"topPost: %@; post(in): %@", topPostsEntity.totalAgainst,post.totalAgainst);

topPostEntity is a Core-Data entity. topPostEntity.totalAgainst is defined as follows:

@property (nonatomic, retain) NSNumber * totalAgainst;

Nothing special in the getter:

- (NSNumber *)totalAgainst
{
    if (!_totalAgainst) _totalAgainst = [[NSNumber alloc]init];
    return _totalAgainst;
}

post.totalAgainst is also defined as an NSNumber as follows:

@property (nonatomic,strong) NSNumber *totalAgainst;

To my shock this is what the log reads:

2013-11-02 00:42:42.476 kello[6260:70b] topPost: 0; post(in): 40000
2013-11-02 00:42:42.476 kello[6260:70b] topPost: -25536; post(in): 40000

How does assigning 40000 to topPostEntity.totalAgainst make it store -25536?

Upvotes: 1

Views: 86

Answers (1)

wholly_cow
wholly_cow

Reputation: 977

Solved the problem.

I had set the core-data entity to Integer 16. I changed this to Integer 64 and that resolved the problem. I'm not sure how anyone's going to find this q to help their problem, but if so - cheers.

Upvotes: 1

Related Questions