I have the following dictionary:
NSDictionary* jsonDict = @{
@"firstName": txtFirstName.text,
@"lastName": txtLastName.text,
@"email": txtEmailAddress.text,
@"password": txtPassword.text,
@"imageUrl": imageUrl,
@"facebookId": [fbId integerValue],
};
In the last element, I need to use an integer, but I am receiving the error:
collection element of type int is not an objective c object
How can I use an int value in this element?
should be:
@"facebookId": [NSNumber numberWithInt:[fbId intValue]];
NSDictionary
works with objects only and as a result, we can't store simply int
s or integer
s or bool
s or anyother primitive datatypes.
[fbId integerValue]
returns a primitive integer value (which is not an object)
Hence we need to encapsulate primitive datatypes and make them into objects. which is why we need to use a class like NSNumber
to make an object to simply store this crap.
more reading: http://rypress.com/tutorials/objective-c/data-types/nsnumber.html
assuming fbID is an int
then It should be like:
@"facebookId": @(fbId)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With