how to create folder structure in documents folder of my iPhone app
I have a folder structure in my server and I need to navigate through that folder a开发者_运维知识库t device side. I receive the folder structure in XML format. My query is :- 1) Can I create the same folder structure in documents folder of my iPhone app.
2) What would be the best approach whether to create folders at device documents folder or just read the XML and show the folders as we parse it(I mean no folder creation).
Waiting for your reply
I'm not 100% sure of your question, but I think this is what you're after...
First, you have to parse the XML from your server. You can do this with the built in NSXMLParser
or with one of the various XML-parsers and document handlers out there. A few alternatives:
- http://code.google.com/p/touchcode/wiki/TouchXML
- http://code.google.com/p/kissxml/
- http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html
Then, you can create directories on your iPhone applications own document folder using the following code. I will assume you have a NSArray
named directories containing some directory names as NSStrings.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [paths objectAtIndex:0];
for (NSString *directory in directories) {
NSString *directoryPath = [storagePath stringByAppendingPathComponent:directory];
[[NSFileManager defaultManager] createDirectoryAtPath: directoryPath attributes:nil];
}
This code is of course very simple and does not include support for adding a entire folder structure (just the first level). But you get the idea.
精彩评论