我有一个像/Test/Demo1/Demo2/Demo3/demo.mp4这样的文件列表,并且想在 Objective-C 中制作 XML 文档。我有一个制作 NSMutableDictionary 的代码:
-(NSMutableDictionary *)addFile:(NSString *)path toTree:(NSMutableDictionary *)tree {
NSMutableDictionary *node = tree;
NSArray *components = [path componentsSeparatedByString:@"/"];
for (NSUInteger i = 0; i < [components count] - 1; i++) {
NSString *key = components[i];
if (node[key] == nil) {
node[key] = [NSMutableDictionary dictionary];
}
node = node[key];
}
NSString *name = [components lastObject];
if ([name length] > 0) {
node[name] = [NSMutableDictionary dictionary];
node = node[name];
}
return node;
}
但我没有好的结果。建议我如何将文件列表转换为 NSMutableArray 或 NSXMLDocument。
谢谢