Objective-C. NSDictionary

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.

@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! :]

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.

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