# Objective-C. NSDictionary

**URL:** <https://forums.kodeco.com/t/objective-c-nsdictionary/40365>\
**Category:** iOS\
**Created:** [March 17, 2018, 2:39am UTC](https://forums.kodeco.com/t/objective-c-nsdictionary/40365 "2018-03-17T02:39:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hcri50](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@hcri50](https://forums.kodeco.com/u/hcri50)\
**Post date:** [March 17, 2018, 2:39am UTC](https://forums.kodeco.com/t/objective-c-nsdictionary/40365/1 "2018-03-17T02:39:52Z")

</div>

NSString \*event = @“DictionaryTest”;  
NSString \*keyword = @“Trinidad Beach”;  
NSInterger keyword\_id = 91234; // I keep crashing when I use NSInterger  
NSString \*story\_id = @“0091234”;

```
_locationsDict = [[NSDictionary alloc] initWithObjectsAndKeys:
                               event, @"event",
                               keyword, @"keyword",
                                keyword_id, @"keyword_id", 
                               story_id, @"story_id", nil];

```

Can someone please tell me why I crash when I use NSInterger, But if I use it as a String, it does not crash. What am I doing wrong please???  
I am in the process of converting the App using CoreData and Swift. But for right now, I need to make a small modification and I simply can not understand why it is crashing using NSInterger.

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [March 17, 2018, 3:50am UTC](https://forums.kodeco.com/t/objective-c-nsdictionary/40365/2 "2018-03-17T03:50:16Z")

</div>

@hcri50 The above code crashes because `NSInteger` is a value type and you can only add reference types like objects or class instances as values to `NSDictionary`. You should convert `NSInteger` to `NSNumber` in this case:

```
NSString *event = @"DictionaryTest";
NSString *keyword = @"Trinidad Beach";
NSInteger keyword_id = 91234; 
NSNumber *number = [NSNumber numberWithInteger: keyword_id];
NSString *story_id = @"0091234";

NSDictionary *_locationsDict = [[NSDictionary alloc] initWithObjectsAndKeys:
                                  event, @"event",
                                  keyword, @"keyword",
                                  number, @"keyword_id",
                                  story_id, @"story_id", nil];
```

Please let me know if you have any more questions or issues regarding the whole thing. Thank you! :]

---

<div class="post-metadata">

**Author:** ![hcri50](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@hcri50](https://forums.kodeco.com/u/hcri50)\
**Post date:** [March 20, 2018, 3:51pm UTC](https://forums.kodeco.com/t/objective-c-nsdictionary/40365/3 "2018-03-20T15:51:49Z")

</div>

Thank you very much and that did the trick. Sorry for taking so long in getting back for I had to deal with a death within the family.  
I have one last item and I will use a different post for this one.  
THANK YOU AGAIN.

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [August 30, 2018, 6:44pm UTC](https://forums.kodeco.com/t/objective-c-nsdictionary/40365/4 "2018-08-30T18:44:57Z")

</div>

This topic was automatically closed after 166 days. New replies are no longer allowed.
