Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can NSDictionary contain different types of objects as values?

Why does the following result in a BAD_ACCESS error?

NSDictionary *header=[[NSDictionary alloc]initWithObjectsAndKeys:@"fred",@"title",1,@"count", nil];

Can you have different types of objects as values in NSDictionary, including another NSDictionary?

like image 332
ChrisP Avatar asked Jan 24 '12 17:01

ChrisP


1 Answers

You can put any type of object into an NSDictionary. So while @"fred" is OK, 1 is not, as an integer is not an object. If you want to put a number in a dictionary, wrap it in an NSNumber:

NSDictionary *header = { @"title": @"fred", @"count": @1 }; 
like image 61
Jeff Kelley Avatar answered Nov 15 '22 07:11

Jeff Kelley