I use Xamarin.ios with the below code:
var dict = NSUserDefaults.StandardUserDefaults.DictionaryForKey("TheDictKey");
if (dict == null)
{
dict = new NSDictionary();
NSUserDefaults.StandardUserDefaults.SetValueForKey(dict,(NSString)"TheDictKey");
}
dateTime = dateTime.ToUniversalTime();
dict[(NSString)"ValueKey"] = new NSString("Value"); //<------ throw exception here
The last sentence alway throw exception "NotSupported".
How can I update the dictionary? Thanks
That is because NSDictionary is immutable. That means that after it is created, you cannot change it. Use NSMutableDictionary for this purpose instead, which is a subclass of NSDictionary.
From Apple's NSDictionary reference:
NSDictionary creates static dictionaries, and NSMutableDictionary creates dynamic dictionaries.
Here: click
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