Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand your problem correctly, this method should be helpful:</p> <pre><code>// Add the path to the tree. Returns the "node" for this path. -(NSMutableDictionary *)addFile:(NSString *)path toTree:(NSMutableDictionary *)tree { NSMutableDictionary *node = tree; // Split path into components: NSArray *components = [path componentsSeparatedByString:@"/"]; // Create all intermediate dictionaries: for (NSUInteger i = 0; i &lt; [components count] - 1; i++) { NSString *key = [components[i] stringByAppendingString:@"/"]; if (node[key] == nil) { node[key] = [NSMutableDictionary dictionary]; } node = node[key]; } // Process last component, which is the file name, // or "" in the case of a dictionary: NSString *name = [components lastObject]; if ([name length] &gt; 0) { node[name] = [NSMutableDictionary dictionary]; node = node[name]; } return node; } </code></pre> <p>If you use it like this:</p> <pre><code>NSArray *files = ...; // Your array of files NSMutableDictionary *tree = [NSMutableDictionary dictionary]; for (NSString *path in files) { NSMutableDictionary *node = [self addFile:path toTree:tree]; BOOL isDir = [path hasSuffix:@"/"]; if (!isDir) { node[@"filename"] = path; } } </code></pre> <p>the resulting dictionary is</p> <pre> { "blog/" = { "code.css" = { filename = "blog/code.css"; }; "style.css" = { filename = "blog/style.css"; }; }; "etc/" = { "awsservices.png" = { filename = "etc/awsservices.png"; }; "speeds.png" = { filename = "etc/speeds.png"; }; "test/" = { "other/" = { "speeds.png" = { filename = "etc/test/other/speeds.png"; }; }; }; }; "site/" = { "dino.png" = { filename = "site/dino.png"; }; "error.css" = { filename = "site/error.css"; }; "main.css" = { filename = "site/main.css"; }; "signet.min.js" = { filename = "site/signet.min.js"; }; }; } </pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload