Advertisement
Guest User

Untitled

a guest
Oct 1st, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. dispatch_group_t readingGroup = dispatch_group_create();
  2.  
  3. NSFileManager* manager = [NSFileManager defaultManager];
  4.  
  5. NSString *docsDir = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Data"];
  6.  
  7. NSDirectoryEnumerator *dirEnumerator = [manager enumeratorAtURL:[NSURL fileURLWithPath:docsDir]
  8. includingPropertiesForKeys:[NSArray arrayWithObjects:NSURLNameKey,
  9. NSURLIsDirectoryKey,nil]
  10. options:NSDirectoryEnumerationSkipsHiddenFiles
  11. errorHandler:nil];
  12.  
  13.  
  14. // An array to store the all the enumerated file names in
  15. NSMutableArray *arrayFiles;
  16.  
  17. // Enumerate the dirEnumerator results, each value is stored in allURLs
  18. for (NSURL *url in dirEnumerator) {
  19.  
  20. // Retrieve the file name. From NSURLNameKey, cached during the enumeration.
  21. NSString *fileName;
  22. [url getResourceValue:&fileName forKey:NSURLNameKey error:NULL];
  23.  
  24. // Retrieve whether a directory. From NSURLIsDirectoryKey, also cached during the enumeration.
  25. NSNumber *isDirectory;
  26. [url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:NULL];
  27.  
  28.  
  29. if (![isDirectory boolValue]) {
  30.  
  31. dispatch_group_enter(readingGroup);
  32. TWReaderDocument* doc = [TWReaderDocument documentFileURL:url withCompletionBlock:^(BOOL success) {
  33.  
  34. dispatch_group_leave(readingGroup);
  35.  
  36. }];
  37.  
  38. [arrayFiles addObject:doc];
  39.  
  40. }
  41. else if ([[[fileName componentsSeparatedByString:@"_" ] objectAtIndex:0] isEqualToString:@"ThalesData"]) {
  42.  
  43. TreeItem* treeItem = [[TreeItem alloc] init];
  44.  
  45. arrayFiles = [NSMutableArray arrayWithCapacity:10];
  46.  
  47. treeItem.child = arrayFiles;
  48. treeItem.nodeName = [[fileName componentsSeparatedByString:@"_" ] lastObject];
  49. [self addItem:treeItem];
  50.  
  51.  
  52. }
  53. }
  54.  
  55. dispatch_group_notify(readingGroup, dispatch_get_main_queue(), ^{ // 4
  56.  
  57. NSLog(@"All concurrent tasks completed");
  58.  
  59. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement