-
Notifications
You must be signed in to change notification settings - Fork 20
/
delegate.js
45 lines (28 loc) · 972 Bytes
/
delegate.js
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
const objc = require('../src/index');
const {
NSFileManager,
NSString,
NSURL
} = objc;
const FileManagerDelegate = objc.createClass('FileManagerDelegate', 'NSObject', {
'fileManager:shouldMoveItemAtPath:toPath:': (self, cmd, fileManager, srcPath, dstPath) => {
console.log('-[NSFileManagerDelegate fileManager:shouldMoveItemAtPath:toPath:]');
return 1;
},
_encodings: {
'fileManager:shouldMoveItemAtPath:toPath:': ['c40', ['@0', ':8', '@16', '@24', '@32']]
}
});
const fm = NSFileManager.new();
const delegate = FileManagerDelegate.new();
fm.setDelegate_(delegate);
const pathA = 'x.txt';
const pathB = 'y.txt';
// create file
const data = objc.ns('hello world').dataUsingEncoding_(4);
fm.createFileAtPath_contents_attributes_(pathA, data, null);
// move file
fm.moveItemAtPath_toPath_error_(pathA, pathB, null);
// delete file
let url = NSURL.fileURLWithPath_(pathB);
fm.trashItemAtURL_resultingItemURL_error_(url, null, null);