An unofficial wrapper around FSEvent tailored for Swift 5.

Overview

EonilFSEvents

Eonil 2018 Maintenance. 2019 Maintenance.

Build Status

It's possible to use FSEvents directly in Swift, but it still involves many boilerplate works and subtle conversions.

This library provides mostly-faithful wrapper around FSEvents feature tailored for Swift 5.

Quickstart

Import.

import EonilFSEvents

Start.

try EonilFSEvents.startWatching( 
    paths: ["/"],
    for: ObjectIdentifier(self),
    with: { event in print(event) })

Stop.

EonilFSEvents.stopWatching(for: ObjectIdentifier(self))

Using Full Features

Make a EonilFSEventStream, schedule it to a GCD queue, and start.

let s = try EonilFSEventStream(pathsToWatch: paths,
    sinceWhen: .now,
    latency: 0,
    flags: [],
    handler: handler)
s.setDispatchQueue(DispatchQueue.main)
try s.start()

After use, deinitialize by stop, invalidate(unschedule).

s.stop()
s.invalidate()

As soon as the last strong reference gets removed, the stream will be destroyed.

Caveats

In the Xcode, AppKit apps are configured to use Sandbox by default. Sandboxed apps cannot access files out of its container. Therefore, it could look like it cannot receive file system events out of the container. To receive file system events out of container, you should turn off sandboxing.

At this point, xcodebuild fails on dependency resolution for packages. I don't know why. It seems Xcode have some issues with it. To work around, just set SYMROOT explicitly. See test.zsh how to set it.

Credits & License

Copyright(c) 2018 Hoon H., Eonil. All rights reserved. Use of this library is granted under "MIT License".

Comments
  • Cannot get this framework to load no matter what I do...

    Cannot get this framework to load no matter what I do...

    When I try to compile I get the following:

    Missing package product 'EonilFSEvents', please fix package resolution errors before building

    What causes this?

    opened by matthewcoxx 4
  • Item Modified Event sent several times.

    Item Modified Event sent several times.

    Hi there, I've got a pointer to an event stream and whenever I hit CMD + S on a file and save it, it tends to call item modified multiple times. Is this intended behavior?

    event_stream

    opened by ZkHaider 3
  • Release FSEventStream when deiniting EonilFSEventStream

    Release FSEventStream when deiniting EonilFSEventStream

    According to Instruments, see the screenshot,

    Screenshot 2022-12-04 at 15 40 38

    it seems that FSEventStream does not get deallocated when EonilFSEventStream is deinited. To test this, I deallocate the event stream when the main window of the Demo app is closed.

    opened by qvacua 2
  • How to store EonilFSEventsEventID?

    How to store EonilFSEventsEventID?

    I'm trying to persist EonilFSEventsEventID to (say) UserDefaults, but it doesn't serialize directly, and I can't get at the tasty raw value inside of it as it's marked internal. Given that the ID is used to catch up on stream events yoiu may have missed, am I missing an easy way to store this object away for future use?

    thx. ben

    opened by osheroff 2
  • don't receive the event when i remove a file inside observed folder

    don't receive the event when i remove a file inside observed folder

    i don't recive an event when i remove a file inside the observed folder, and when i create a file inside the observed folder i have an event but it's 4 seconds after

    let paths: [String] = [file.url.absoluteString]
    let handler = { event in
        print(event)
    }
    let s = try EonilFSEventStream(pathsToWatch: paths,
                                   sinceWhen: .now,
                                   latency: 0,
                                   flags: [.fileEvents, .noDefer],
                                   handler: handler)
    s.setDispatchQueue(DispatchQueue.main)
    try s.start()
    
    opened by amine2233 1
  • EonilFSEventStream crashing viewDidLoad

    EonilFSEventStream crashing viewDidLoad

    in viewDidLoad():

      func goGet(_ fmtLogPath: String) throws {
        let s = try EonilFSEventStream(
          pathsToWatch: [fmtLogPath],
          sinceWhen: .now,
          latency: 3,
          flags: [.noDefer, .fileEvents],
          handler: { event in print(event) }
        )
        s.setDispatchQueue(DispatchQueue.main)
        try s.start()
      }
    
      public override func viewDidLoad() {
        super.viewDidLoad()
    
        try! self.goGet(fmtLogPath)
    }
    

    fmtLogPath: /Users/mike/Documents/Mikeumus/Log/Test2/

    Results in: Screen Shot 2021-06-25 at 8 46 39 PM


    EonilFSEvents.startWatching() does work for me in viewDidLoad() however:

        try! EonilFSEvents.startWatching(
            paths: [fmtLogPath],
            for: ObjectIdentifier(self),
            with: { event in print(event) })
    

    isn't startWatching like the same thing,... ๐Ÿค”

    Thank you for any insight ๐Ÿ™‡๐Ÿปโ€โ™‚๏ธ

    +1 for ๐Ÿ’– GitHub Sponsors and Discussions!

    opened by mikeumus 1
  • How can i get this working in background thread?

    How can i get this working in background thread?

    I plan to monitor multiple folders and start each task in an 'Operation' But the 'startWatching' method fails the assertion.

    What can we do here to monitor multiple folders?

    opened by kamleshgk 1
  • "historyDone" flag and "sinceWhen: .now"

    If I understand well the comment to historyDone flag, there should be an history of all changes happened in the folder before starting to monitor FSEvents. When done, it will notify the event flagged historyDone. Is there a way to silence all historical events?

    It also says that .historyDone

    It will not be sent if kFSEventStreamEventIdSinceNow was passed for sinceWhen.

    But using the suggested method in readme, default is .now but the flag is produced anyway. Shouldn't it silence all historical events? Should filter them by hand in my handler?

    Thank you.

    opened by gioele-santi 1
Owner
eonil
Hobo.
eonil
๐Ÿ’ก A light Swift wrapper around Objective-C Runtime

A light wrapper around Objective-C Runtime. What exactly is lumos? lumos as mentioned is a light wrapper around objective-c runtime functions to allow

Suyash Shekhar 139 Dec 19, 2022
UTIKit is an UTI (Uniform Type Identifier) wrapper for Swift.

UTIKit UTIKit is an UTI (Uniform Type Identifier) wrapper for Swift. Features UTIKit is a full featured library including entire UTI functions. Conver

Hiroki Kato 254 Nov 27, 2022
A Swift property wrapper which stores the previous value

swift-with-previous A Swift property wrapper which stores the previous value. The previous value can be get by the projected value $propertyName. impo

IKEDA Sho 3 Feb 22, 2022
Swift wrapper for PuLP module.

SwiftPuLP Wraps Python Linear Programming PuLP module. Requirements Requires PuLP to be installed, and may require PYTHON_LIBRARY environment variable

Michel Tilman 0 Dec 24, 2021
Coz profiler Swift wrapper/bindings

Swift Coz (Linux Only) Coz profiler Swift wrapper/bindings. This is a Swift wrapper around the Coz profiler here: https://github.com/plasma-umass/coz

Krzysztof Majk 4 Aug 5, 2022
A swift wrapper for NSTimer

Every.Swift - A Convenient NSTimer Wrapper Usage Provided that your class implement TimerManageable protocol you just do: self.every(3.seconds) {

Samhan Salahuddin 271 Apr 14, 2022
A Swift wrapper for URL bookmarks which allow a file to be located regardless of whether it is moved or renamed.

Bookmark A Swift wrapper for URL bookmarks which allow a file to be located regardless of whether it is moved or renamed. This class wraps Swift's URL

Darren Ford 8 Nov 3, 2022
Backports the new @Invalidating property wrapper to older platforms

ViewInvalidating A property wrapper that backports the new @Invalidating property wrapper to older versions of iOS/tvOS/macOS. For more information on

Suyash Srijan 61 Nov 23, 2022
Dungeon Crawl: Stone Soup iOS Webtiles wrapper

dcss-ios Dungeon Crawl: Stone Soup iOS Webtiles wrapper Summary This project aims to make DCSS webtiles a joy to play on any iOS device without an ext

Jon Lazar 2 Aug 10, 2022
Contacts wrapper for iOS 9 or upper with Objective-C

ContactsWrapper Contacts wrapper for iOS 9 or upper with Objective-C. For the information translated to Russian, take a look at this link. Requirement

Abdullah Selek 22 Jun 18, 2022
StoredIn is a simple property wrapper library to store any value in anywhere

StoredIn StoredIn is a simple property wrapper library to store any value in anywhere. Installation Please use the Swift Package Manager. dependencies

Henrique Sasaki Yuya 2 Jul 4, 2022
`Republished` is a property wrapper enabling nested ObservableObjects in SwiftUI.

Republished The @Republished proprty wrapper allows an ObservableObject nested within another ObservableObject to naturally notify SwiftUI of changes.

Adam Zethraeus 13 Dec 5, 2022
BCSwiftTor - Opinionated pure Swift controller for Tor, including full support for Swift 5.5 and Swift Concurrency

BCSwiftTor Opinionated pure Swift controller for Tor, including full support for

Blockchain Commons, LLC โ€” A โ€œnot-for-profitโ€ benefit corporation 4 Oct 6, 2022
Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Apple 2k Dec 28, 2022
Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer documentation.

Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer docum

Apple 833 Jan 3, 2023
Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. (Pure Swift, Supports Linux)

SwiftFoundation Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. Goals Provide a cross-platform in

null 620 Oct 11, 2022
Swift - โœ๏ธSwift ๊ณต๋ถ€ ์ €์žฅ์†Œโœ๏ธ

Swift ์Šค์œ„ํ”„ํŠธ์˜ ๊ธฐ์ดˆ 1. Swift์˜ ๊ธฐ๋ณธ 2. ๋ณ€์ˆ˜์™€ ์ƒ์ˆ˜ [3. ๋ฐ์ดํ„ฐ ํƒ€์ž… ๊ธฐ๋ณธ] [4. ๋ฐ์ดํ„ฐ ํƒ€์ž… ๊ณ ๊ธ‰] 5. ์—ฐ์‚ฐ์ž 6. ํ๋ฆ„ ์ œ์–ด 7. ํ•จ์ˆ˜ 8. ์˜ต์…”๋„ ๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ๊ณผ ์Šค์œ„ํ”„ํŠธ 9. ๊ตฌ์กฐ์ฒด์™€ ํด๋ž˜์Šค 10. ํ”„๋กœํผํ‹ฐ์™€ ๋ฉ”์„œ๋“œ 11. ์ธ์Šคํ„ด์Šค ์ƒ

Jiwon 0 Mar 9, 2022
__.swift is a port of Underscore.js to Swift.

__.swift Now, __.swift is version 0.2.0! With the chain of methods, __.swift became more flexible and extensible. Documentation: http://lotz84.github.

Tatsuya Hirose 86 Jun 29, 2022
SNTabBarDemo-Swift - Cool TabBar With Swift

SNTabBarDemo-Swift Cool TabBar How To Use // MARK: - setup private func setu

iAnchor 3 Sep 29, 2022