How to convert bool to NSObject in MonoTouch

c#, mono, nsuserdefaults, xamarin.ios

Solution

That's how I do it:

using (var defaults = NSDictionary.FromObjectsAndKeys (new object[] {
        true,
    }, new object [] {
        "AllowInternetAccess",
    })) {

    settings.RegisterDefaults (defaults);
}

Of course I have more than one key/value pair and this allows me to avoid several calls to a `NSMutableDictionary`.

Problem

This is making me a little crazy. I'm trying to register some NSUserDefaults in my MonoTouch app. ``` var defaultsToRegister = new NSMutableDictionary(); defaultsToRegister.SetValueForKey(true, IS_REMINDING); NSUserDefaults.StandardUserDefaults.RegisterDefaults(defaultsToRegister); ``` Obviously this isn't compiling because a bool cannot be converted to NSObject. But when I want to set or retrieve a boolean value from NSUserDefaults I can use: ``` public bool IsReminding { get { return NSUserDefaults.StandardUserDefaults.BoolForKey(IS_REMINDING); } set { NSUserDefaults.StandardUserDefaults.SetBool(value, IS_REMINDING); } } ``` In the settings plist file the boolean is written as `<key>ReminderTimeOfDay</key><true/>` which is what I would expect. So how to register a default boolean value?

Original source