soh335 / filewatch Goto Github PK
View Code? Open in Web Editor NEWSimple FSEvents wrapper for Swift
License: MIT License
Simple FSEvents wrapper for Swift
License: MIT License
Running carthage update
fails due to a build problem. I'm running mac OS Sierra and XCode 9.2. Here's the build that goes wrong:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/dan/Documents/XCode/Syncer/Syncer/Carthage/Checkouts/FileWatch/FileWatch/FileWatch.swift -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -I /Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/Build/Intermediates.noindex/ArchiveIntermediates/FileWatch/BuildProductsPath/Release -F /Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/Build/Intermediates.noindex/ArchiveIntermediates/FileWatch/BuildProductsPath/Release -g -module-cache-path /Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/ModuleCache -swift-version 3 -serialize-debugging-options -report-errors-to-debugger -Xcc -I/Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/Build/Intermediates.noindex/ArchiveIntermediates/FileWatch/IntermediateBuildFilesPath/FileWatch.build/Release/FileWatch.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/Build/Intermediates.noindex/ArchiveIntermediates/FileWatch/IntermediateBuildFilesPath/FileWatch.build/Release/FileWatch.build/FileWatch-generated-files.hmap -Xcc -I/Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/Build/Intermediates.noindex/ArchiveIntermediates/FileWatch/IntermediateBuildFilesPath/FileWatch.build/Release/FileWatch.build/FileWatch-own-target-headers.hmap -Xcc -I/Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/Build/Intermediates.noindex/ArchiveIntermediates/FileWatch/IntermediateBuildFilesPath/FileWatch.build/Release/FileWatch.build/FileWatch-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/Build/Intermediates.noindex/ArchiveIntermediates/FileWatch/IntermediateBuildFilesPath/FileWatch.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/Build/Intermediates.noindex/ArchiveIntermediates/FileWatch/IntermediateBuildFilesPath/FileWatch.build/Release/FileWatch.build/FileWatch-project-headers.hmap -Xcc -I/Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/Build/Intermediates.noindex/ArchiveIntermediates/FileWatch/BuildProductsPath/Release/include -Xcc -I/Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/Build/Intermediates.noindex/ArchiveIntermediates/FileWatch/IntermediateBuildFilesPath/FileWatch.build/Release/FileWatch.build/DerivedSources/x86_64 -Xcc -I/Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/Build/Intermediates.noindex/ArchiveIntermediates/FileWatch/IntermediateBuildFilesPath/FileWatch.build/Release/FileWatch.build/DerivedSources -Xcc -working-directory/Users/dan/Documents/XCode/Syncer/Syncer/Carthage/Checkouts/FileWatch -emit-module-doc-path /Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/Build/Intermediates.noindex/ArchiveIntermediates/FileWatch/IntermediateBuildFilesPath/FileWatch.build/Release/FileWatch.build/Objects-normal/x86_64/FileWatch~partial.swiftdoc -serialize-diagnostics-path /Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/Build/Intermediates.noindex/ArchiveIntermediates/FileWatch/IntermediateBuildFilesPath/FileWatch.build/Release/FileWatch.build/Objects-normal/x86_64/FileWatch.dia -O -parse-as-library -module-name FileWatch -emit-module-path /Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/Build/Intermediates.noindex/ArchiveIntermediates/FileWatch/IntermediateBuildFilesPath/FileWatch.build/Release/FileWatch.build/Objects-normal/x86_64/FileWatch~partial.swiftmodule -emit-dependencies-path /Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/Build/Intermediates.noindex/ArchiveIntermediates/FileWatch/IntermediateBuildFilesPath/FileWatch.build/Release/FileWatch.build/Objects-normal/x86_64/FileWatch.d -emit-reference-dependencies-path /Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/Build/Intermediates.noindex/ArchiveIntermediates/FileWatch/IntermediateBuildFilesPath/FileWatch.build/Release/FileWatch.build/Objects-normal/x86_64/FileWatch.swiftdeps -o /Users/dan/Library/Caches/org.carthage.CarthageKit/DerivedData/9.2_9C40b/FileWatch/0.0.1/Build/Intermediates.noindex/ArchiveIntermediates/FileWatch/IntermediateBuildFilesPath/FileWatch.build/Release/FileWatch.build/Objects-normal/x86_64/FileWatch.o
/Users/dan/Documents/XCode/Syncer/Syncer/Carthage/Checkouts/FileWatch/FileWatch/FileWatch.swift:138:64: error: C function pointer signature '(ConstFSEventStreamRef, UnsafeMutableRawPointer?, Int, UnsafeMutableRawPointer, UnsafePointer<FSEventStreamEventFlags>?, UnsafePointer<FSEventStreamEventId>?) -> Void' (aka '(OpaquePointer, Optional<UnsafeMutableRawPointer>, Int, UnsafeMutableRawPointer, Optional<UnsafePointer<UInt32>>, Optional<UnsafePointer<UInt64>>) -> ()') is not compatible with expected type 'FSEventStreamCallback' (aka '@convention(c) (OpaquePointer, Optional<UnsafeMutableRawPointer>, Int, UnsafeMutableRawPointer, UnsafePointer<UInt32>, UnsafePointer<UInt64>) -> ()')
private static let StreamCallback: FSEventStreamCallback = {(streamRef: ConstFSEventStreamRef, clientCallBackInfo: UnsafeMutableRawPointer?, numEvents: Int, eventPaths: UnsafeMutableRawPointer, eventFlags: UnsafePointer<FSEventStreamEventFlags>?, eventIds: UnsafePointer<FSEventStreamEventId>?) -> Void in
^
The sample code in the README uses NSRunLoop.currentRunLoop()
. This has since been renamed to RunLoop.current
. Thanks!
I copied the FileWatch.swift file into my app and using it to monitor folders on OSX 10.11.6. I start monitoring file system events without any errors but noticed the callback never gets called. My initial app was sandboxed, so thinking that could have something to do with it, I created a test app, copied the code in, without any changes, and got the same results. Callback events are not fired.
Also added the FileWatchTests file and run the tests; the testFileCreate
test fails after the timeout, because the event callback is not called before timeout expires. Here's the test output
Test Suite 'Selected tests' started at 2016-12-09 00:00:10.505
Test Suite 'TodoListTests.xctest' started at 2016-12-09 00:00:10.506
Test Suite 'FileWatchTests' started at 2016-12-09 00:00:10.506
Test Case '-[TodoListTests.FileWatchTests testInitCreateFlag]' started.
Test Case '-[TodoListTests.FileWatchTests testInitCreateFlag]' passed (0.001 seconds).
Test Case '-[TodoListTests.FileWatchTests testFileCreate]' started.
file:///var/folders/hq/0bs9lngs3x79f31k1tndcxbm0000gn/T/AEE80BF5-A560-47C7-B8DD-F0E34BF69E31-75021-0002DAC9BBDDE8A4_file.txt
/************/TodoList/TodoListTests/FileWatchTests.swift:63: error:
-[TodoListTests.FileWatchTests testFileCreate] :
Asynchronous wait failed: Exceeded timeout of 10 seconds, with unfulfilled expectations: "".
Test Case '-[TodoListTests.FileWatchTests testFileCreate]' failed (10.171 seconds).
Test Suite 'FileWatchTests' failed at 2016-12-09 00:00:20.679.
Executed 2 tests, with 1 failure (0 unexpected) in 10.172 (10.173) seconds
Test Suite 'TodoListTests.xctest' failed at 2016-12-09 00:00:20.680.
Executed 2 tests, with 1 failure (0 unexpected) in 10.172 (10.174) seconds
Test Suite 'Selected tests' failed at 2016-12-09 00:00:20.680.
Executed 2 tests, with 1 failure (0 unexpected) in 10.172 (10.175) seconds
Any ideas why this would happen?
Your code works. Awesome!
But i had to comment out the deinit call. I guess deinit is taken care of by swift now?
I cant reach any outside variable in this scope:
var temp:String = "test"
let filewatch = try! FileWatch(paths: ["/path/to/dir"], createFlag: [.UseCFTypes, .FileEvents], runLoop: NSRunLoop.currentRunLoop(), latency: 3.0, eventHandler: { event in
print(self.temp)//<---this doesn't work
if event.flag.contains(.ItemIsFile) {
debugPrint(event.path)
}
})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.