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

yalag

Suspended
Original poster
Nov 18, 2007
1,448
81
Trying to save some objects to file on the iphone, this method seems
to be the way to do it NSKeyedArchiver:archiveRootObject:toFile but
not sure what the file path should be. I tried a single filename
"test" and it got created at /test on my desktop which is probably not
going to work on real devices. Any ideas?
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Here is code for getting the absolute path of "test" inside the application's documents folder (you can read more about this in the iPhone programming guide):
Code:
NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filename = [docsPath stringByAppendingPathComponent:@"test"];
 

Hardan

macrumors newbie
Nov 10, 2008
2
0
Still having it wrong

Here is code for getting the absolute path of "test" inside the application's documents folder (you can read more about this in the iPhone programming guide):
Code:
NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filename = [docsPath stringByAppendingPathComponent:@"test"];

this is kinda noobish but i still seem to be unnable to archieve an object... I have this object, called scoreKeeper (member of the ScoreKeeper class i designed. It conforms to NSCoding and all) but i can`t seem to encode it =/

should i create the test file explicidly or something?

This is what i do:

NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filename = [docsPath stringByAppendingPathComponent:mad:"test"];
BOOL result = [NSKeyedArchiver archiveRootObject: scoreKeeper toFile: filename];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.