title: Objective c - Weird behavior with int
body: <p>I have an object that stores a property as an int.</p>
  
  <p>When in the console I type <code>po menuItem.quantity</code> I get a <code>1</code> which is what I'm expecting.</p>
  
  <p>If I try to use that to populate a label with this line of code:</p>
  
  <pre><code>label_Quantity.text=[NSString stringWithFormat:@"%d", menuItem.quantity];
  </code></pre>
  
  <p>I instead get a <code>414280896</code></p>
  
  <p>Also, please have a look at the following image:</p>
  
  <p><img src="https://i.stack.imgur.com/NVG18.png" alt="enter image description here"></p>
  
  <p>For some reason it says <code>_quantity = (int) 414280896</code>but when I click on the <code>i</code> icon, I get a <code>1</code>.</p>
  
  <p>What is going on here?</p>
  
  <p>EDIT 1:</p>
  
  <p>Per a commenter's request, this is MenuItemDTO:</p>
  
  <pre><code>@interface MenuItemDTO : NSObject
  
  @property (nonatomic) int menuItemID;
  @property (nonatomic, strong) NSString* name;
  @property (nonatomic, strong) NSString* description;
  @property (nonatomic) int quantity;
  @property (nonatomic, strong) NSString* imageURL;
  @property (nonatomic) int categoryID;
  @property (nonatomic) float price;
  @property (nonatomic) BOOL isSponsoredItem;
  @property (nonatomic, strong) NSDate* lastModifiedDate;
  
  @end 
  </code></pre>
  
  <p>And it got created like this:</p>
  
  <pre><code>MenuItemDTO * menuItem = [MenuItemDTO new];
  menuItem.quantity = [Converter fromDictionaryValueToInt:[json objectForKey:@"Quantity"]];
  </code></pre>
  
  <p>json is an NSDictionary with different values coming from a web service. </p>
  
  <p><code>Converter fromDictionaryValueToInt</code> looks like this:</p>
  
  <pre><code>+ (int)fromDictionaryValueToInt:(NSNumber *)value
  {
      if ([value isKindOfClass:[NSNull class]])
          return 0;
  
      return [value intValue];
  }
  </code></pre>
  
  <p>EDIT 2:</p>
  
  <p>I found the problem, but don't understand why it didn't work.
  The problem didn't come when initializing. That was working just fine. It looks like later in the code, quantity was being assigned another value like this:</p>
  
  <pre><code>menuItem.quantity = (int)[dict objectForKey:@"Total"];
  </code></pre>
  
  <p>That was giving the problem with the weird number. Now I'm doing this:</p>
  
  <pre><code>menuItem.quantity = [Converter fromDictionaryValueToInt:[dict objectForKey:@"Total"]];
  </code></pre>
  
  <p>And it's working fine. If anyone can explain to me why the first method didn't work, I'll select that answer. Otherwise, I'll put this myself later and select mine.</p>
  
  <p>Thanks to the commenters for helping me out. </p>