Baxter Lopez
Baxter Lopez

Reputation: 1129

How to make a path in objective C?

I'm working with Objective C (IOS) and I found this code:

Person *aPerson = <#Get a Person#>;
NSString *archivePath = <Path for the archive#>;
BOOL success = [NSKeyedArchiver archiveRootObject:aPerson toFile:archivePath];

I would like to know what the archivePath should be to save the file in documents directory.

Thank you

Upvotes: 0

Views: 86

Answers (1)

Dany Joumaa
Dany Joumaa

Reputation: 2040

To figure out archivePath:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);  
NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory 
NSString *archivePath = [documentsPath stringByAppendingPathComponent:@"Person"];

Upvotes: 1

Related Questions