int ramdomnumber = arc4random_uniform(900000) + 100000;
[[NSUserDefaults standardUserDefaults] setObject:ramdomnumber forKey:@"contactno"];
[[NSUserDefaults standardUserDefaults] synchronize];
i tried the above code but it showing the error like implicit conversion of 'int' to 'id_nullable' is disallowed with ARC.can anyone suggest me how to store the int value in the nsuserdefaults .
The error occurs because you are passing a scalar type to a method which expects an object.
There is a dedicated method, it's good programming habit to cast the value to the expected type;
NSInteger ramdomnumber = (NSInteger)(arc4random_uniform(900000) + 100000);
[[NSUserDefaults standardUserDefaults] setInteger:ramdomnumber forKey:@"contactno"];
// [[NSUserDefaults standardUserDefaults] synchronize];
synchronize is not needed.
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