Become a MacRumors Supporter for $25/year with no ads, private forums, and more!
  • Did you order new AirTags? We've opened a dedicated AirTags forum.

yalag

macrumors 65816
Original poster
Nov 18, 2007
1,373
65
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
6
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"];
 
Comment

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];
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.