Skip to content

Commit ad08f90

Browse files
add README
1 parent 047a1a8 commit ad08f90

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# RxFileMonitor
2+
3+
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
4+
5+
RxSwift `Observable` wrapper for CoreFoundation file system events.
6+
7+
## Usage
8+
9+
The most convenient usage is through the RxSwift `Observable` exposed in the module as:
10+
11+
```swift
12+
Monitoring.folderMonitor(url: URL) -> Observable<FolderContentChangeEvent>
13+
```
14+
15+
You use it on a folder and will be notified about ...
16+
17+
- changes to the folder itself, and
18+
- changes to any item inside it (not including sub-folders).
19+
20+
Example:
21+
22+
```swift
23+
import RxFileMonitor
24+
25+
let disposeBag = DisposeBag()
26+
let folderUrl = URL(fileURLWithPath: "/path/to/monitor/")
27+
28+
Monitoring.folderMonitor(url: folderUrl)
29+
.subscribe(onNext: { event in
30+
print("Folder contents changed at \(event.url) (\(event.change))")
31+
})
32+
.addDisposableTo(disposeBag)
33+
```
34+
35+
### Reacting to file content changes only
36+
37+
Say you want to update a cache of a folder's notes' contents, you'll be interested in files only:
38+
39+
```swift
40+
let changedFile = Monitoring.folderMonitor(url: folderUrl)
41+
// Files only ...
42+
.filter { $0.change.contains(.isFile) }
43+
// ... except the Spotlight cache.
44+
.filter { $0.filename != ".DS_Store" }
45+
.map { $0.filename }
46+
.observeOn(MainScheduler.instance)
47+
```
48+
49+
Now you will want to update the cache for the changed file:
50+
51+
```swift
52+
changedFile.subscribe(onNext: cache.updateFile)
53+
```
54+
55+
Or if you simply rebuild the whole cache when anything changed, you can stop after filtering for accepted events:
56+
57+
```swift
58+
let changedFile = Monitoring.folderMonitor(url: folderUrl)
59+
.filter { $0.change.contains(.isFile) }
60+
.filter { $0.filename != ".DS_Store" }
61+
.observeOn(MainScheduler.instance)
62+
.subscribe(onNext: { _ in
63+
cache.rebuild()
64+
})
65+
```
66+
67+
## License
68+
69+
Copyright (c) 2016 Christian Tietze.
70+
71+
Distributed under The MIT License:
72+
73+
Permission is hereby granted, free of charge, to any person obtaining a copy
74+
of this software and associated documentation files (the "Software"), to deal
75+
in the Software without restriction, including without limitation the rights
76+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
77+
copies of the Software, and to permit persons to whom the Software is
78+
furnished to do so, subject to the following conditions:
79+
80+
The above copyright notice and this permission notice shall be included in all
81+
copies or substantial portions of the Software.
82+
83+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
84+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
85+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
86+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
87+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
88+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
89+
SOFTWARE.

RxFileMonitor.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
5096B2B61DD2216B00076058 /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = Carthage/Build/Mac/RxSwift.framework; sourceTree = "<group>"; };
6464
5096B2BB1DD221D700076058 /* Monitoring.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Monitoring.swift; sourceTree = "<group>"; };
6565
5096B2C01DD22D6000076058 /* FolderContentChangeEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FolderContentChangeEvent.swift; sourceTree = "<group>"; };
66+
5096B2C21DD22FC200076058 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
67+
5096B2C41DD2333E00076058 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
6668
50E835431DD1B26900783B62 /* RxFileMonitor.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RxFileMonitor.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6769
50E835461DD1B26900783B62 /* RxFileMonitor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RxFileMonitor.h; sourceTree = "<group>"; };
6870
50E835471DD1B26900783B62 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -122,6 +124,8 @@
122124
50E835391DD1B26900783B62 = {
123125
isa = PBXGroup;
124126
children = (
127+
5096B2C41DD2333E00076058 /* README.md */,
128+
5096B2C21DD22FC200076058 /* LICENSE */,
125129
50E835451DD1B26900783B62 /* RxFileMonitor */,
126130
50E835501DD1B26900783B62 /* RxFileMonitorTests */,
127131
50E835621DD1B28400783B62 /* Example */,

0 commit comments

Comments
 (0)