tags:

views:

41

answers:

1

Hi All,

I have 4 database catalogues in my app, i will be switching the four catalogues. When i start the app, i read the NSUserDefaults and try to load the default catalogue in the memory, but in the first time this doesnt happen. Instead i get null values returned first time just because the DB connection is not successful for some unknown reason, the debugger is unable to go there too.

But the app starts up the next time, the values are fetched successfully.

Please help

+1  A: 

If your trying to fetch some necessary data from the user defaults, it might not be there the first time you run the app. You probably need to create a default set of defaults (heh) using:

-[NSUserDefaults registerDefaults:]

...before you query the user defaults for any value.

From User Defaults Programming Topics

The registration domain is a set of application-provided defaults that are used unless a user overrides them (the “default defaults” or “factory settings”). For example, the first time you run Xcode, there isn’t an IndexOnOpen value saved in your defaults database. Consequently, Xcode registers a default value for IndexOnOpen in the NSRegistrationDomain as a “catch all” value. Xcode can thereafter assume that an NSUserDefaults object always has a value to return for the default, simplifying the use of user defaults.

You set NSRegistrationDomain defaults programmatically with the method registerDefaults:.

TechZen
Thanks a lot TechZen, Its a good insight by you. Helped a lot
Futur