Why is the value changing when I cast an int to an NSInteger?

74 views Asked by At

I have an NSDictionary, and I perform objectForKey for key resource_type_id:

NSInteger resourceTypeID = [self.selectedDictionary objectForKey:@"resource_type_id"];

When I print resourceTypeID in the console, it returns 2 (the correct ID).

Now, I need to convert this NSInteger to an int to feed into my switch case statement.

Here is that code:

self.resourceTypeLabel.text = [ResourceType getResourceTypeFromResourceTypeID:(int)resourceTypeID];

However, when I do this, self.resourceTypeLabel.text returns nil. Upon further inspection, when printing (int)resourceTypeID in the console, it returns 35.

Why is the number changing when I cast it?

1

There are 1 answers

3
Christian Schnorr On

-objectForKey: should return an object of type id, not an int. How are you setting the value?