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 05-24-2010, 06:34 AM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 9
ruiter is on a distinguished road
Unhappy saving multiple nsstring into one savefile

I'm stuck at one of the last parts of my iApp, can someone help me?

I want to add different field entries of different .m files into one file without overwriting the file. (I also dont know how to make that save file btw).

I have 2 .h files with :

file1 : NSString *dataHML;
NSString *dataHML2;

file2 : NSString *dataHML3;
NSString *dataHML4;

I have in the first file1.m file :

-(IBAction)FirstSelection:(id)sender {
UIImage *img = [UIImage imageNamed:@"sf5.png"]; [displayCharacterHML setImage:img];

if (count == 5)
{ UIImage *img = [UIImage imageNamed:@"High-s.png"];
if (img != nil) {
[displayHML setImage:img];
dataHML = [[NSString alloc] initWithFormat:@"H"];
count = 6;
}
}

-(IBAction)SecondSelection:(id)sender {
UIImage *img = [UIImage imageNamed:@"sf6.png"]; [displayCharacterHML setImage:img];
if (count == 5)
{ UIImage *img = [UIImage imageNamed:@"Medium-s.png"];
if (img != nil) { [displayHML2 setImage:img];
dataHML2 = [[NSString alloc] initWithFormat:@"M"]; count = 6;
}}}

then in the second file2.m i have :

-(IBAction)ThirdSelection:(id)sender {
UIImage *img = [UIImage imageNamed:@"sf6.png"]; [displayCharacterHML setImage:img];

if (count == 5)
{ UIImage *img = [UIImage imageNamed:@"High-s.png"];
if (img != nil) {
[displayHML3 setImage:img];
dataHML3 = [[NSString alloc] initWithFormat:@"H"];
count = 6;
}
}

-(IBAction)SecondSelection:(id)sender {
UIImage *img = [UIImage imageNamed:@"sf6.png"]; [displayCharacterHML setImage:img];

if (count == 5)
{ UIImage *img = [UIImage imageNamed:@"Medium-s.png"];
if (img != nil) { [displayHML4 setImage:img];
dataHML4 = [[NSString alloc] initWithFormat:@"M"];
count = 6; } }

How do i make the dataHML, dataHML2, dataHML3 and dataHML4 being saved into one save file with each on their own line?

If you can explain me this ill be very grateful, i've red things with NSUserdefault etc. but i couldn't make allot of sense of it since my question is quite specific.

Last edited by ruiter; 05-24-2010 at 06:40 AM.
ruiter is offline   Reply With Quote
Old 05-24-2010, 08:43 PM   #2 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 35
atticusalien is on a distinguished road
Default

Code:
NSData *dataToWrite = [[NSString stringWithFormat:@"%@\n%@",dataHML, dataHML2] dataUsingEncoding:NSUTF8StringEncoding];

NSString *docsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSString *path = [docsDirectory stringByAppendingPathComponent:@"fileName.txt"];
NSFileHandle *myHandle = [NSFileHandle fileHandleForUpdatingAtPath:path];

[myHandle seekToEndOfFile];
[myHandle writeData:data];
[myHandle closeFile];

Last edited by atticusalien; 05-24-2010 at 09:53 PM.
atticusalien is offline   Reply With Quote
Reply

Bookmarks

Tags
data, nsstring, nsuserdefaults, objective-c, save

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: 307
10 members and 297 guests
ajay123123, ashaman64, baja_yu, ChrisYates, guusleijsten, HemiMG, newDev, pkIDSF, Sami Gh, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,113
Posts: 402,878
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

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