• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: how do I check the defaults for an object?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how do I check the defaults for an object?


  • Subject: Re: how do I check the defaults for an object?
  • From: Sherm Pendley <email@hidden>
  • Date: Sat, 27 May 2006 13:39:42 -0400

On May 27, 2006, at 1:17 PM, Alan Smith wrote:

I need to get an array from UserDefaults but the first time this app
is run there won't be that array. That's not the only time either. So,
I need to check to see if that array exists so the app doesn't crash,

You need to provide a sensible "default defaults" dictionary that will be used if the user hasn't provided their own. You want to do that early in your app's lifetime - like in - applicationWillFinishLaunching:. Here's an example - it's in Perl, but the idea is still clear; you'd call the same methods in Objective-C.


	my $defaults = NSUserDefaults->standardUserDefaults();
	my $appDefaults = {
		'docSets' => [
			{ 'name' => '* Default *',
			  'podPath' => $Config{'privlib'}.'/pods',
			  'corePath' => $Config{'privlib'},
			  'cpanPath' => $Config{'sitelib'},
			  'vendorPath' => $Config{'vendorlib'},
			  'arch' => $Config{'archname'}
			 },
		   ],
		'ClearCacheOnExit' => 0,
		'ShowTip' => 1,
		'ShowIntro' => 1,
		'CacheDir' => NSHomeDirectory() . '/Library/Caches/ShuX',
		'StylesheetType' => 0,
    };
    $defaults->registerDefaults($appDefaults);

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >how do I check the defaults for an object? (From: "Alan Smith" <email@hidden>)

  • Prev by Date: Re: region for window draggging
  • Next by Date: You can give propertyListFromData: a C string!
  • Previous by thread: how do I check the defaults for an object?
  • Next by thread: Re: how do I check the defaults for an object?
  • Index(es):
    • Date
    • Thread