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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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-09-2011, 02:51 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 9
W1tchcr4ft is on a distinguished road
Default Best way to save data?

hey guys, my app i´m coding on right now needs to save one String.
So I was wondering, if its better to write it in a .plis or save it in a file?
I failed on both ways...
could you please give me a link to a tutorial?
Would be wonderfull!
greetz,
W1tchcr4ft
W1tchcr4ft is offline   Reply With Quote
Old 02-09-2011, 03:03 PM   #2 (permalink)
Registered Member
 
Chobie's Avatar
 
Join Date: Feb 2011
Location: UK
Posts: 115
Chobie is on a distinguished road
Default

Quote:
Originally Posted by W1tchcr4ft View Post
hey guys, my app i´m coding on right now needs to save one String.
So I was wondering, if its better to write it in a .plis or save it in a file?
I failed on both ways...
could you please give me a link to a tutorial?
Would be wonderfull!
greetz,
W1tchcr4ft
You should use a plist for a single string. Also learn to search on the Apple's Developer's Resources.
__________________
Chobie is offline   Reply With Quote
Old 02-09-2011, 03:25 PM   #3 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 651
kapps11 is on a distinguished road
Default

for just one string, i would use NSUserDefaults, its a framework layed on top of plists. saving your string would be like this -

Code:
[[NSUserDefaults standardUserDefaults] setObject:myString forKey:@"MyStringKey"];
Loading…
kapps11 is offline   Reply With Quote
Old 02-14-2011, 01:35 PM   #4 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 9
W1tchcr4ft is on a distinguished road
Default

Quote:
Originally Posted by kapps11 View Post
for just one string, i would use NSUserDefaults, its a framework layed on top of plists. saving your string would be like this -

Code:
[[NSUserDefaults standardUserDefaults] setObject:myString forKey:@"MyStringKey"];
Loading…
wow, thanx, but does that realy work without declaring anything before?
or do i just have to declare one String from what the MyStringKey will be taken?
greetz, w1tchcr4ft
W1tchcr4ft is offline   Reply With Quote
Old 02-14-2011, 01:52 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 324
mariano_donati is on a distinguished road
Default

You don't need to declare anything. You can just retrieve your string with:

Code:
NSString* mySavedString = [[NSUserDefaults standardUserDefaults] stringForKey:@"MyStringKey"]
mariano_donati is offline   Reply With Quote
Old 02-14-2011, 08:09 PM   #6 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 26
tobban2 is on a distinguished road
Default

Quote:
Originally Posted by Chobie View Post
You should use a plist for a single string. Also learn to search on the Apple's Developer's Resources.
If I want to save several strings(uitextfields) and states of segmentedcontrolers. Just a simple "save" button, and then a "load" button. How do I do that?

EDIT:
save:
Code:
 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	[defaults setObject:[NSNumber numberWithInt:[feedProvider selectedSegmentIndex]] forKey:@"feedProvider"];
	[defaults synchronize];
load:
Code:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
feedProvider.selectedSegmentIndex = [[defaults objectForKey:@"feedProvider"] intValue];
Easy way to do it with several segmentedControlers?

Edit2:
When trying to save text:
Code:
myString = [[NSString alloc] intWithFormat:textfield.text];
[textfield setText:myString];
NSUserDefaults *stringDefault = [NSUserDefaults standardUserDefaults];
[stringDefault setObject:myString forKey:@"stringKey"];
- this works but gives warning.
initWithString changed to stringWithString - no warning but app crarshes. Why?

Last edited by tobban2; 02-15-2011 at 07:46 AM.
tobban2 is offline   Reply With Quote
Reply

Bookmarks

Tags
file, plist, save, 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: 373
14 members and 359 guests
blasterbr, buggen, Clouds, dre, EvilElf, jeroenkeij, jimmyon122, Mah6447, n00b, nyoe, pungs, Sami Gh, stanny, toon4413
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,121
Posts: 402,900
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

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