Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-19-2009, 04:55 PM   #1 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 6
Default NSUserDefaults... is it possible?

It is possible to set a text field in the Root.plist (ie a username) as a preference and also have a preference (also the username) built on a flipside view which will update the one in the plist when set there? I assume one can do this with [NSUserDefaults standardUserDefaults]; but I am having trouble making it work. Thank you for any advice.
markieb is offline   Reply With Quote
Old 07-19-2009, 05:33 PM   #2 (permalink)
Former NeXTStep Developer
 
Join Date: Mar 2009
Posts: 997
Default

Quote:
Originally Posted by markieb View Post
It is possible to set a text field in the Root.plist (ie a username) as a preference and also have a preference (also the username) built on a flipside view which will update the one in the plist when set there? I assume one can do this with [NSUserDefaults standardUserDefaults]; but I am having trouble making it work. Thank you for any advice.
If Root.plist is in the app bundle, then you can't update it there because the main bundle is read only.

It's certainly possible to have a default username in that plist, but to keep the actual one you want to save in the user defaults.

joe
FlyingDiver is offline   Reply With Quote
Old 07-19-2009, 09:06 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 557
Default

Hi:

I have a username in the preference specifiers section of root.plist and I am able to change it in the "settings" view in my app and the reset value persists.

Is the other section of the plist readonly?

Joseph
Joseph Nardone is offline   Reply With Quote
Old 07-19-2009, 10:20 PM   #4 (permalink)
Former NeXTStep Developer
 
Join Date: Mar 2009
Posts: 997
Default

Quote:
Originally Posted by Joseph Nardone View Post
Hi:

I have a username in the preference specifiers section of root.plist and I am able to change it in the "settings" view in my app and the reset value persists.

Is the other section of the plist readonly?

Joseph
You mean the Root.plist of Settings.bundle? It's not actually changing the contents of the plist, it's saving the new value in the user defaults. Which are stored elsewhere.

joe
FlyingDiver is offline   Reply With Quote
Old 07-20-2009, 12:47 AM   #5 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 6
Default This is why I am having a problem

I was working from an example which set a new perefence from the flipside view controller which was reflected back in the bundle settings. Seems to work with sliders and buttons but I can't get a string to do so. I am struggling as a newbie but I am dedicated. If I know "I can" do it then I will find the way. If I am attempting the impossible then it might take longer! Cheers.
markieb is offline   Reply With Quote
Old 07-20-2009, 12:48 AM   #6 (permalink)
Registered Member
 
Forsworn's Avatar
 
Join Date: Oct 2008
Location: Germany
Posts: 504
Default

Like already said, the settings.bundle saves its content to the NSUserDefaults.

You have to specify a key for the username field, let's say it's SEUsername.

In your app you can get it with this code:
Code:
[[NSUserDefaults standardDefaults] objectForKey:@"SEUsername"]
and modify it:
Code:
[[NSUserDefaults standardDefaults] setObject:myNewUsername forKey:@"SEUsername"]
edit:
And the .plist file where the user defaults are stored is located in the Preferences Directory of your app.
Forsworn is offline   Reply With Quote
Old 07-20-2009, 04:20 PM   #7 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 6
Default thanks

thisnk you... I have been using exactly that for days so I am doing someother thing wrong! I am going to start from scratch and rebuild that section and see where I went wrong the last time. At least now I can be assured that "it is" possible so I can put aside my fear that I was barking up the wrong tree. Cheers.
markieb is offline   Reply With Quote
Old 07-21-2009, 12:40 AM   #8 (permalink)
Former NeXTStep Developer
 
Join Date: Mar 2009
Posts: 997
Default

You might want to post the actual code you're using to save the string. Maybe someone else can spot the problem.

joe
FlyingDiver is offline   Reply With Quote
Reply

Bookmarks

Tags
flipside, nsuserdefaults, preferences

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 244
13 members and 231 guests
2WeeksToGo, AdamL, ADY, BrianSlick, Dani77, Dattee, headkaze, mer10, mgon987, timle8n1, Touchmint, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,879
Threads: 89,228
Posts: 380,745
Top Poster: BrianSlick (7,129)
Welcome to our newest member, mgon987
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:46 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0