Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Japi

macrumors newbie
Original poster
Nov 15, 2006
16
0
I have a very basic question about how to a write a NSString to a file. I have tryed the following way, but it doesn't seem to work:

NSString *filePath = [[NSBundle mainBundle] pathForResource:mad:"Gameinf" ofType:mad:"txt"];
NSString* st = @"a1";
[st writeToFile:filePath atomically:FALSE encoding:NSUTF8StringEncoding error:nil];

And also just:

NSString* st = @"a1";
[st writeToFile:mad:"Gameinf.txt" atomically:FALSE encoding:NSUTF8StringEncoding error:nil];

I would just want to save the game level, where the player. So that the player could continue from that level, when he restarts the program.

Any help would be appreciated.
 
Wirelessly posted (Mozilla/5.0 (iPod; U; CPU iPhone OS 3_1_2 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7D11 Safari/528.16)

An easier way to do this is just to use NSUserDefaults.
 
Thanks for the info, dejo! I didn't know about that before (just started iphone developing). It worked like a charm.

Just a bit confused, why didn't the write to a file work. I tested a code that read from a file, and it worked just fine.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.