Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C dictionary inserting a BOOL

OK, I'm a little confused. It's probably just a triviality.

I've got a function which looks something like this:

- (void)getNumbersForNews:(BOOL)news andMails:(BOOL)mails { NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init]; [parameters setValue:news  forKey:@"getNews"]; [parameters setValue:mails forKey:@"getMails"];...} 

It doesn't matter whether I use setValue:forKey: or setObject:ForKey:, I'm always getting a warning:

"Passing argument 1 of set... makes pointer from integer without a cast"...

How on earth do I insert a bool into a dictionary?

like image 538
Infinite Avatar asked Jan 21 '10 09:01

Infinite


1 Answers

Values in an NSDictionary must be objects. To solve this problem, wrap the booleans in NSNumber objects:

[parameters setValue:[NSNumber numberWithBool:news] forKey:@"news"]; [parameters setValue:[NSNumber numberWithBool:mails] forKey:@"mails"]; 
like image 74
Steve Harrison Avatar answered Oct 05 '22 02:10

Steve Harrison