int x = 5;
int t = 6;
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:@"books.book", @"og:type",
@"www.goodreads.com", @"og:url",
@"Snow Crash", @"og:title",
@"978-3-16-148410-0",@"books:isbn",
@"http://en.wikipedia.org/wiki/File:Snowcrash.jpg", @"og:image",
@"www.google.com",@"og:audio:url",
@"www.facebook.com",@"al:windows_universal:url",
@"www.facebook.com",@"al:windows_phone:url",
@"www.facebook.com",@"al:windows:url",
@"www.facebook.com",@"al:iphone:url",
@"www.facebook.com",@"al:ipad:url",
x,@"books:rating:value",
t,@"books:rating:scale",
@"In reality, Hiro Protagonist delivers pizza for Uncle Enzo’s CosoNostra Pizza Inc., but in the Metaverse he’s a warrior prince. Plunging headlong into the enigma of a new computer virus that’s striking down hackers everywhere, he races along the neon-lit streets on a search-and-destroy mission for the shadowy virtual villain threatening to bring about infocalypse. Snow Crash is a mind-altering romp through a future America so bizarre, so outrageous…you’ll recognize it immediately.", @"og:description",
@"Science Fiction",@"books:genre",
@"eu_es",@"books:language:locale",
@[@"en_us",@"ca_es",@"cs_cz"],@"books:language:alternate",nil];
As you can see above I'm trying to create a Dictionary, however whenever i run the code i get error like this.
2014-06-11 23:50:50.338 TestApp[8374:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSDictionary dictionaryWithObjectsAndKeys:]: second object of each pair must be non-nil. Or, did you forget to nil-terminate your parameter list?'
*** First throw call stack:
(
0 CoreFoundation 0x00000001019ef495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010174e99e objc_exception_throw + 43
2 CoreFoundation 0x00000001019d27e3 +[NSDictionary dictionaryWithObjectsAndKeys:] + 1043
3 TestApp 0x000000010000724d -[CYCViewController postBooks:] + 1021
4 UIKit 0x00000001002fcf06 -[UIApplication sendAction:to:from:forEvent:] + 80
5 UIKit 0x00000001002fceb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
6 UIKit 0x00000001003d9880 -[UIControl _sendActionsForEvents:withEvent:] + 203
7 UIKit 0x00000001003d8dc0 -[UIControl touchesEnded:withEvent:] + 530
8 UIKit 0x0000000100333d05 -[UIWindow _sendTouchesForEvent:] + 701
9 UIKit 0x00000001003346e4 -[UIWindow sendEvent:] + 925
10 UIKit 0x000000010030c29a -[UIApplication sendEvent:] + 211
11 UIKit 0x00000001002f9aed _UIApplicationHandleEventQueue + 9579
12 CoreFoundation 0x000000010197ed21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
13 CoreFoundation 0x000000010197e5f2 __CFRunLoopDoSources0 + 242
14 CoreFoundation 0x000000010199a46f __CFRunLoopRun + 767
15 CoreFoundation 0x0000000101999d83 CFRunLoopRunSpecific + 467
16 GraphicsServices 0x0000000103b66f04 GSEventRunModal + 161
17 UIKit 0x00000001002fbe33 UIApplicationMain + 1010
18 TestApp 0x0000000100008153 main + 115
19 libdyld.dylib 0x00000001020875fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I've followed solutions by adding NILbut still doesn't work. Everything is well placed. I checked and checked.
The values which can be nil
in your dictionary are x
and t
. The above error says the object can't be nil
, you can't put nil
in place of an object of a key in a dictionary, instead you can try to put @""
or even you can supply [NSNull null]
.
Update
As you are trying to put
int x = 5;
int t = 6;
the above values are non-object values, a dictionary requires object, try put.
[NSNumber numberWithInt:x]
[NSNumber numberWithInt:t]