[MonoTouch] NSUserDefaults

Kevin Daly kevindaly at xtra.co.nz
Tue Aug 25 02:40:22 EDT 2009

Ahhhh, that makes sense (more head clutching ensues).

-----Original Message-----
From: Miguel de Icaza [mailto:miguel at novell.com] 
Sent: Tuesday, 25 August 2009 10:29 a.m.
To: Kevin Daly
Cc: monotouch at lists.ximian.com
Subject: Re: [MonoTouch] NSUserDefaults


> //Attempting to retrieve a value:
> String username =
> NSUserDefaults.StandardUserDefaults.StringForKey("UserName");

This is a simple fix, StandardUserDefaults is a method, not a  
property, so you need:

NSUserDefaults.StandardUserDefaults ().StringForKey ("UserName");

Perhaps we need to turn this into a property.   If I get a chance, I  
will commit such change.

> //Attempting to set a value (testing with bool since I can't find a  
> method
> for strings or objects...should we use indexers?):
> bool haveStuff = true;
> NSUserDefaults.StandardUserDefaults.SetBool(haveStuff,"HaveStuff");
> I'm pretty sure I'm using these incorrectly - I've used the  
> Objective-C
> versions successfully (a minor miracle in itself) but clearly I'm  
> missing
> something in extrapolating the usage for MonoTouch
> (I've established just now (since I started writing this) that  
> creating an
> instance of NSUserDefaults works, including persistence: e.g.  
> NSUserDefaults
> defaults = new NSUserDefaults(); And I can use an indexer with that  
> to store
> an NSString that can be initialised from and cast to a String.
> Not what I expected but it seems to do the job)
> PS. Sorry it took me a while to provide the example but as you know  
> that's
> the trouble with widely disparate time zones (GMT+12 here). I've  
> been busy
> sleeping the sleep of the perplexed.
> -----Original Message-----
> From: Miguel de Icaza [mailto:miguel at novell.com]
> Sent: Sunday, 23 August 2009 6:27 a.m.
> To: Kevin Daly
> Cc: monotouch at lists.ximian.com
> Subject: Re: [MonoTouch] NSUserDefaults
> Hello,
>    This means that you are using a method without the parameter
> arguments, so the compiler complains in that case.
>    Can you paste your sample code?
> On Aug 22, 2009, at 4:43 AM, Kevin Daly wrote:
>> Can anyone give an example of successfully using
>> NSUserDefaults.StandardUserDefaults (using the current build)?
>> Anything I try using either indexers or Set... methods simply gives
>> me the
>> following error:
>> "Expression denotes a 'method group', where a 'variable', 'value' or
>> 'type'
>> was expected (CS0119)".
>> Same goes for trying to retrieve a value (well actually I was trying
>> to
>> retrieve null, since I obviously hadn't managed to set anything).
>> It seems I'm doing something seriously wrong, so I'd love to know  
>> what
>> works.
>> _______________________________________________
>> MonoTouch mailing list
>> MonoTouch at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/monotouch

More information about the MonoTouch mailing list