Hello, I'm designing an application that reads data to the iPod touch/iPhone that is sent to it via multicast sockets with UDP and I need to store it as a file in a document directory. Does that exist on on the iPhone or iPod Touch? I know there is NSFileHandle and NSFileManager, which is what I plan on using, to take care of reading and writing to the file, but I'm not sure where the "My Documents" section of the iPod touch is if you know what I'm saying. I am not familiar with the iPod/iPhone file directory that well yet, so any help is appreciated! Is there some kind of "general" directory that all developers use to store their files in if they have any involved in their application?
+6
A:
You should use your application's Documents directory to store persistent files. You can get the path to the directory using this function, which Apple includes in their template for an application using Core Data:
/**
Returns the path to the application's documents directory.
*/
- (NSString *)applicationDocumentsDirectory {
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
return basePath;
}
Tim
2009-07-12 03:04:00
+1
A:
More recently, the template for a Core Data application provides code like this:
- (NSString *)applicationDocumentsDirectory {
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}
If the returned NSArray from NSSearchPathForDirectoriesInDomains is empty, lastObject returns nil, so as a result, the code is shorter and cleaner.
macbirdie
2010-10-04 13:28:52