0
我有一個文檔及其路徑的列表。使用Cocoa-Touch從文件路徑創建樹形結構對象
Unsigned/Corporate Tax Return/Testing.docx
Signed/Report/fieldsInfo.pdf
Unsigned/Corporate Tax Return/testSecure.pdf
Unsigned/Corporate Tax Return/2012/fileCatcher.pdf
Unsigned/Corporate Tax Return/2012/taxReturn.pdf
由此我想一個樹狀結構的對象數組,其中所有這些對象都放在 我有兩個對象類型:文檔和文件
我怎麼會去的目標C這樣做呢?
我有這麼遠:
- (void) createFolderStructure:(Document *) doc{
Folder * root = [[Folder alloc]init];
NSArray * folders = [doc.documentFilePath componentsSeparatedByString:@"/"];
for(NSString * folderName in folders){
if([root.folderSubFolders count] == 0){
//root is empty , create folder
Folder * newFolder = [[Folder alloc]init];
newFolder.folderName = folderName;
[root.folderSubFolders addObject:newFolder];
} else {
//root has subfolders
for(Folder * folder in root.folderSubFolders){
if ([folder.folderName isEqualToString:folderName]) {
//folder exists in subfolders
} else {
//folder doesn't exist ,create folder
Folder * newFolder = [[Folder alloc]init];
newFolder.folderName = folderName;
[root.folderSubFolders addObject:newFolder];
}
}
}
}
}