[MacRuby-devel] NSUserDefaults and registerDefaults

Steve Clarke steve at sclarkes.me.uk
Fri Mar 16 09:21:50 PDT 2012


Hi Erik,

The following code works for me, though as far as I can see it's effectively the same as yours.  The only difference might be that I run this code in rb_main.rb  rather than after the app has finished launching.

DBNAME_KEY='database_name'
DEFAULTS = NSUserDefaults.standardUserDefaults
appDefaults = { DBNAME_KEY=>'bamford'}
DEFAULTS.registerDefaults(appDefaults)
puts DEFAULTS.stringForKey(DBNAME_KEY) => "bamford" if the key is not present in the plist.


Steve


On 16 Mar 2012, at 15:19, Erik Lundqvist wrote:

> Sean,
> 
> Thank you, but that only demonstrates the bit I have working. What is not working for me is using registerDefaults.
> 
> Thanks anyway :)
> 
> On 16 March 2012 13:32, Sean Mateus <seanlilmateus at googlemail.com> wrote:
> Hi Erik,
> 
> here is an example app Matt wrote:
>    save: https://github.com/mattetti/LiveTV/blob/master/TVFrancaise/AppDelegate.rb#L249-253
>    read: https://github.com/mattetti/LiveTV/blob/master/TVFrancaise/AppDelegate.rb#L41-42
> 
> I hope this will help you
> 
> 
> -- Sean Mateus
> 
> 
> On Friday, March 16, 2012 9:59:38 AM UTC+1, Erik Lundqvist wrote:
> Hi All,
> 
> It's time for my first newbie question :)
> Trying to save some default values for user preferences, but failing pretty hard. I was hoping someone would have successfully used NSUserDefaults registerDefaults, and could point me in the right direction.
> 
>     def applicationDidFinishLaunching(a_notification)
> 
> 
>         app_defaults = {"wcff.magic_key" => "hello world"}
> 
>         NSUserDefaults.standardUserDefaults.registerDefaults(app_defaults)
> 
>         NSUserDefaults.standardUserDefaults.synchronize
> 
> 
>     end
> 
> 
> 
> Elsewhere in the code...
> 
> 
> 
> 
>         @magic_key = NSUserDefaults.standardUserDefaults["wcff.magic_key"]
> 
>         puts "magic_key#{@magic_key}"
> 
> 
> 
> It just prints out "magic_key"...
> 
> 
> 
> Actually setting a value in standardUserDefaults seems to work fine, like this
> 
> NSUserDefaults.standardUserDefaults["wcff.magic_key"] = "hello you"
> 
> But I want a default
> 
> 
> 
> Anyone?
> 
> 
> 
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
> 
> 
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20120316/9a0780e8/attachment-0001.html>


More information about the MacRuby-devel mailing list