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 02-22-2009, 05:39 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 34
Question How Can I Store A String So That I Can Use It The Next Time My App Runs?

My application doesn't have "settings", but I do need to store 3 strings that will not be deleted as soon as my app closes. I need to be able to edit the strings and then store them so that my app can use them next time it runs to monitor the user's completion of a task. I'm confused about "Settings.bundle". Is that even what I need? Please be thorough in explanations. I'm new to Mac OS X and iPhone development. Thanks
hank863 is offline   Reply With Quote
Old 02-22-2009, 05:44 PM   #2 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,890
Default

Check out NSUserDefaults its what you want
__________________
I really do this.
Bertrand21 is online now   Reply With Quote
Old 02-22-2009, 05:57 PM   #3 (permalink)
Tutorial Author
 
Steaps's Avatar
 
Join Date: Oct 2008
Location: Ontario, Canada
Posts: 466
Default

iPhone Programming Tutorial - Saving/Retrieving Data Using NSUserDefaults | iCodeBlog
Steaps is offline   Reply With Quote
Old 02-22-2009, 07:17 PM   #4 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Germany
Age: 26
Posts: 243
Default

Quote:
Originally Posted by hank863 View Post
My application doesn't have "settings", but I do need to store 3 strings that will not be deleted as soon as my app closes. I need to be able to edit the strings and then store them so that my app can use them next time it runs to monitor the user's completion of a task. I'm confused about "Settings.bundle". Is that even what I need? Please be thorough in explanations. I'm new to Mac OS X and iPhone development. Thanks
To save when your application is about to exit

Code:
        NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
	[prefs setInteger:myNumber1 forKey:@"myNumber1"];
        [prefs setInteger:myNumber2 forKey:@"myNumber2"];
	[prefs synchronize];
And to load them

Code:
        NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
	 myNumber1 = [prefs integerForKey:@"myNumber1"];
	myNumber2 = [prefs integerForKey:@"myNumber2"];
__________________
-Hosam
hosam is offline   Reply With Quote
Old 02-22-2009, 07:42 PM   #5 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 34
Default

Thank you very much everyone! This is exactly what I need. I know it's off topic, but could one of you please give me the line of code for checking to see whether a NSString contains a set of characters?
hank863 is offline   Reply With Quote
Old 02-22-2009, 07:48 PM   #6 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 34
Default

Just found this
Code:
 [myString rangeOfString:@"bla"].location != NSNotFound
If you have a better way, please post it. Thanks again for your help.
hank863 is offline   Reply With Quote
Old 02-22-2009, 07:50 PM   #7 (permalink)
Tutorial Author
 
Steaps's Avatar
 
Join Date: Oct 2008
Location: Ontario, Canada
Posts: 466
Default

Quote:
Originally Posted by hank863 View Post
Just found this
Code:
 [myString rangeOfString:@"bla"].location != NSNotFound
If you have a better way, please post it. Thanks again for your help.
Thanks! I hope this works, i don't need it now so i'm not testing it but i will probably need it in the future.
Steaps is offline   Reply With Quote
Reply

Bookmarks

Tags
data, permanent, store, string

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: 281
20 members and 261 guests
ADY, Bertrand21, Dani77, HemiMG, iDifferent, IphoneSdk, jakerocheleau, JasonR, jimbo, macquitzon216, MACralik, mer10, NSeven, prchn4christ, Rudy, silverwiz, spiderguy84, Sunny46
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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