Giter Club home page Giter Club logo

filewatch's Introduction

Build Status Carthage compatible

FileWatch

Simple FSEvents wrapper for Swift

INSTALL

CARTHAGE

  • Add github "soh335/FileWatch" to your Cartfile.
  • Run carthage update.
  • Add FileWatch.framework to Embedded Binaries.

USAGE

import FileWatch

let filewatch = try! FileWatch(paths: ["/path/to/dir"],  createFlag: [.UseCFTypes, .FileEvents], runLoop: RunLoop.current, latency: 3.0, eventHandler: { event in
    if event.flag.contains(.ItemIsFile) {
      debugPrint(event.path)
    }
})

LICENSE

  • MIT

filewatch's People

Contributors

soh335 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

srj0x0

filewatch's Issues

Accessing variables outside the scope of the eventHandler scope

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)
    }
})

README update

The sample code in the README uses NSRunLoop.currentRunLoop(). This has since been renamed to RunLoop.current. Thanks!

Event callback not being fired

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?

carthage update fails, compile error

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
                                                               ^

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.