-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeleteDocument.codesnippet
More file actions
49 lines (44 loc) · 1.89 KB
/
deleteDocument.codesnippet
File metadata and controls
49 lines (44 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDECodeSnippetCompletionPrefix</key>
<string>document_delete</string>
<key>IDECodeSnippetCompletionScopes</key>
<array>
<string>ClassImplementation</string>
</array>
<key>IDECodeSnippetContents</key>
<string>- (void)deleteDocument:(UIDocument *)document withCompletionBlock:(void (^)())completionBlock {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
NSError *fileCoordinatorError = nil;
[[[NSFileCoordinator alloc] initWithFilePresenter:nil] coordinateWritingItemAtURL:document.fileURL options:NSFileCoordinatorWritingForDeleting error:&fileCoordinatorError byAccessor:^(NSURL *newURL) {
// extra check to ensure coordinator is not running on main thread
NSAssert(![NSThread isMainThread], @"Must be not be on main thread");
// create a fresh instance of NSFileManager since it is not thread-safe
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSError *error = nil;
if (![fileManager removeItemAtURL:newURL error:&error]) {
NSLog(@"Error: %@", error);
// TODO handle the error
}
if (completionBlock) {
completionBlock();
}
}];
});
}</string>
<key>IDECodeSnippetIdentifier</key>
<string>67823B27-1A69-4AB1-B341-7830FBA0FD62</string>
<key>IDECodeSnippetLanguage</key>
<string>Xcode.SourceCodeLanguage.Objective-C</string>
<key>IDECodeSnippetSummary</key>
<string>document_delete</string>
<key>IDECodeSnippetTitle</key>
<string>Delete Document</string>
<key>IDECodeSnippetUserSnippet</key>
<true/>
<key>IDECodeSnippetVersion</key>
<integer>2</integer>
</dict>
</plist>