A micro-framework for observing file changes, both local and remote. Helpful in building developer tools.

Related tags

Files KZFileWatchers
Overview

KZFileWatchers

Demo GIF

CI Status Version License Platform

Wouldn't it be great if we could adjust feeds and configurations of our native apps without having to sit back to Xcode, change code, recompile and navigate back to screen we were at?

One of the basis of building tools that allow us to do just that is the way we observe for data changes, this micro-framework provides you File observers for Local and Remote assets.

This framework provides:

  • FileWatcher.Local useful for observing local file changes, it can also be used to breach Sandbox env for debug simulator builds and e.g. observe file on the developer desktop (like the demo app does).

  • FileWatcher.Remote can be used to observe files on the web, it supports both Etag headers and Last-Modified-Date so you can just put file on Dropbox or real ftp server.

It also supports usage from Objective-C projects. For this, you should consider these following steps:

  1. Add $(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME) into your projects Library Search Paths in Build Setting section.

  2. Import swift-header by adding @import KZFileWatchers; into any .m file, where you want to use FileWatchers.

  3. Use provided classes for set up file observing like this:

self.fileWatcher = [[LocalFileWatcher alloc] initWithPath:path];
self.fileWatcher.delegate = self;
[self.fileWatcher startWithError:nil];
  1. Implement FileWatcherDelegate in your class for handling file refreshing events. For example:
- (void)refreshDidOccurFrom:(id<FileWatcherProtocol>)fileWatcher type:(enum RefreshResult)type data:(NSData *)data
{
    self.textLabel.text = [[NSString alloc] initWithData:data encoding:kCFStringEncodingUTF8];
}

Installation

KZFileWatchers is available through CocoaPods and Swift Package Manager.

CocoaPods

In order to install KZFileWatchers by using CocoaPods, simply add the following line to your Podfile:

pod "KZFileWatchers"

Last version to support Swift 2.3 is 0.1.2 Last version to support Swift 3.0 is 1.0.4

Swift Package Manager

Installing KZFileWatchers over SwiftPM is only supported since version 1.0.1. You just need to add it as a dependency to your Package.swift manifest:

import PackageDescription

let package = Package(
    name: "YourTarget",
    dependencies: [
        .Package(url: "https://github.com/krzysztofzablocki/KZFileWatchers.git", majorVersion: 1),
    ]
)

Author

Krzysztof Zabłocki, [email protected]

Contributing

Contributions to KZFileWatchers are welcomed and encouraged! Please see the Contributing guide.

A list of contributors is available through GitHub.

To give clarity of what is expected of our members, KZFileWatchers has adopted the code of conduct defined by the Contributor Covenant. This document is used across many open source communities. For more, see the Code of Conduct.

License

KZFileWatchers is available under the MIT license. See LICENSE for more information.

Comments
  • Objc Interoperability

    Objc Interoperability

    Hi, I want to add interoperability with Objective-C by writing some wrappers above classes and enum, without modifying original sources. It could be useful for project with legacy code base.

    opened by morzv 6
  • TextEdit is breaking the dispatch_source observation

    TextEdit is breaking the dispatch_source observation

    Hi there, Thanks for this project. I am trying this out at present but I am not sure how it works.In the sample source example ,when I run the app and open the text file the changes that are typed in the text file are reflected on the app only when the file is saved . This happens only the first time , rest of the time if I change the text and save again nothing gets changed. This is contrary to what is happening in the GIF that has been attached to the project. Please tell tell how to make sure it works that way.

    bug 
    opened by uutkarshsingh 5
  • [Question] KZFileWatchers Fatal Error, Xcode 8.2.1, Swift 3.0.2

    [Question] KZFileWatchers Fatal Error, Xcode 8.2.1, Swift 3.0.2

    Hi, from New Zealand! :-)

    I like the idea of this framework and hopefully will be using it in an app I am developing, along with Freddy (for JSON data), and ReSwift (reactive states).

    I downloaded this repo on 20 April 2017, and put only the source files into my project.

    Recently, I have had a fatal runtime error on this piece of code in the Daemon class: try! fileWatcher.start(closure: { result in

    The full error is this: fatal error: 'try!' expression unexpectedly raised an error: trips.FileWatcher.Error.failedToStart("Failed to open file"): file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-800.0.63/src/swift/stdlib/public/core/ErrorType.swift, line 178

    As seen in this screenshot of Xcode: http://imgur.com/a/cVQZT

    I have adapted the Daemon code to initialize with an URL, then pass that as a path String to FileWatcher.Local as: fileWatcher = FileWatcher.Local(path: String(describing: jsonURL))

    This is shown by the full URL (where 'Store' and 'state.trip' both exist): file:///Users/mikenorman/Library/Developer/CoreSimulator/Devices/72D4C7B2-B12E-4E0D-B520-A194237BCABA/data/Containers/Data/Application/FCA0A655-5F08-40C9-AAF4-0658C8346439/Library/Store/state.trip

    I am currently testing this to the iPhone 6s Simulator, which is working fine for any other builds. The file I am trying to 'watch' is a JSON file (state.trip) in a 'Store' folder in the app's Library folder.

    Is this an invalid operation for the i386 architecture? I only want to use this on iOS. Thread 1: EXC_BAD_INSTRUCTION (code=EXC_i386_INVOP, subcode=0x0)

    I am not sure why it is throwing that fatal error, and any help will be awesome.

    Thanks

    --mike

    opened by ghost 4
  • Added SwiftPM support

    Added SwiftPM support

    Adding SwiftPM support for https://github.com/krzysztofzablocki/Sourcery/issues/28 requires KZFileWatchers to support it too.

    If you want, I can add SwiftPM as additional installation method to your README.md. As SwiftPM currently doesn't support iOS, shall I just add swift build to .travis.yml? This would at least ensure, that the Package.swift file format is correct.

    In order to finish support for SwiftPM, you need to schedule a new release and tag.

    opened by vknabel 3
  • Bad implementation of time intervals

    Bad implementation of time intervals

    you have a bug in your computation of default time intervals. 1/60 is an action on integers which results in a rounded number, specifically in a '0'

    you should change the expression into: '1/60.0' if you want a floating point expression

    opened by ArkadiGiniApps 2
  • Support newest Xcode & Swift

    Support newest Xcode & Swift

    Hi, I would like to update the project to Xcode 9.3 and Swift 4.1. I would love to make PR but firstly I want to hear if this change is wanted or not. I noticed that used pods versions are very old and that some small code improvements can be done.

    opened by tomassliz 2
  • Carthage support

    Carthage support

    opened by TofPlay 2
  • Bug/callback not on main thread

    Bug/callback not on main thread

    This PR fixes the following 2 things:

    1. The test cases were not getting compiled due to a linker issue in the Nimble pod
    2. The test cases were getting failed randomly due to concurrent behavior in the RemoteFileWatcher protocol It not only fixes the test cases but also the expected behaviour from a networking library to get a callback on the main thread.

    Code Changes

    The callback was executed on the main thread in Remote.swift The Podfile was updated to have a post-installation script which fixes the linker issue

    opened by SandeepAggarwal 1
  • Update for Xcode 9.3 & Swift 4.1

    Update for Xcode 9.3 & Swift 4.1

    The example project and framework itself were updated to support Xcode 9.3 and Swift 4.1. This PR resolves #13.

    I had some problems with a correct Travis CI settings, therefore my previous attempted PR's were closed.

    opened by tomassliz 1
  • Update for Xcode 9.3 & Swift 4.1

    Update for Xcode 9.3 & Swift 4.1

    The example project and framework itself were updated to support Xcode 9.3 and Swift 4.1.

    I have a two question:

    1. How are supported other platforms - tvOS and macOS. They are both specified in the podspec file but I don't understand, how they are build because the framework itself is set to support iOS only.

    2. Should not be in the Example's Podfile specified the system and its version? Because the example project is iOS only and when pod update is executed, the warning bellow is shown:

    [!] Automatically assigning platform ios with version 8.0 on target KZFileWatchers_Example because no platform was specified. Please specify a platform for this target in your Podfile. See https://guides.cocoapods.org/syntax/podfile.html#platform.

    I hope that this PR will help.

    opened by tomassliz 1
  • fix: detect changes made by vim

    fix: detect changes made by vim

    After the change made to fix #2, changes made by vim and MacVim aren't detected. This fix is arguably hack-ish — it involves a one-time retry with a delay when we can't find the file to restart observing —, but given how vim seems to do this strange thing where saving a file seems to be delete it and then created the replacement with the same filename..

    Note that with this retry, there's this strange behaviour (supposedly due to how vim works):

    1. Save file in MacVim
    2. Changes get detected, this can continue to work a few times ...
    3. Save file in MacVim
    4. Can't find file to restart restart observing
    5. Retry once, look for the file to restart observing
    6. Changes gets detected correctly

    There's a strange pause of a few seconds between 5-6. If you switch away from vim (if in Terminal) or in MacVim.app, it resumes immediately.

    I'd be happy if there's a better way to make this work for vim/MacVim though :)

    opened by hboon 1
Releases(1.0.6)
Owner
Krzysztof Zabłocki
Dev, Speaker, Creator. Currently Lead iOS @NYTimes My code powers up more than 70 000 apps.
Krzysztof Zabłocki
Edit a file, create a new file, and clone from Bitbucket in under 2 minutes

Edit a file, create a new file, and clone from Bitbucket in under 2 minutes When you're done, you can delete the content in this README and update the

Nikunj Munjiyasara 0 Nov 9, 2021
FileKit is a Swift framework that allows for simple and expressive file management.

FileKit is a Swift framework that allows for simple and expressive file management.

Nikolai Vazquez 2.2k Jan 7, 2023
FileExplorer is a powerful iOS file browser that allows its users to choose and remove files and/or directories

FileExplorer (iOS 9.0+) ?? Project created and maintained by Rafał Augustyniak. You can find me on twitter (@RaAugustyniak). Introduction FileExplorer

Rafał Augustyniak 717 Dec 19, 2022
File management and path analysis for Swift

Pathos offers cross-platform virtual file system APIs for Swift. Pathos is implement from ground-up with on each OS's native API. It has zero dependen

Daniel Duan 104 Nov 19, 2022
zip file I/O library for iOS, macOS and tvOS

ZipZap is a zip file I/O library for iOS, macOS and tvOS. The zip file is an ideal container for compound Objective-C documents. Zip files are widely

Glen Low 1.2k Dec 27, 2022
Zero-setup P2P file transfer between Macs and iOS devices

?? Ares Zero-setup* P2P file transfer between Macs and iOS devices Ares is a service that I built in under 24 hours, winning first place at HackED 201

Indragie Karunaratne 131 Jan 10, 2022
RavynOS File manager built in Cocoa/Appkit and ObjC

Filer A file manager and re-implementation of macOS's Finder. A key component of ravynOS, Filer is the first application you see after you start ravyn

RavynSoft 8 Oct 3, 2022
NV_MVVM-C is a template file generator. This can reduce the time taken to write the boilerplate code and create the files.

NV_MVVM-C Template, is an MVVM-C Boilerplate generator which will help you generate all the necessary files for your project architected in MVVM-C.

Nikhil Vinod 9 Sep 6, 2022
'Root' filesystem File Provider extension for iOS.

RootFSProvider This sample project was previously available on on Patreon. It is written in Objective-C, and has not been updated for newer APIs since

Steven Troughton-Smith 14 Sep 24, 2022
Finder-style iOS file browser written in Swift

FileBrowser iOS Finder-style file browser in Swift 4.0 with search, file previews and 3D touch. Simple and quick to use. Features ✨ Features ?? Browse

Roy Marmelstein 1.5k Dec 16, 2022
🎹 MIDIKit extension for SMF (Standard MIDI File)

?? SMF (Standard MIDI File) Extension for MIDIKit This extension adds abstractions for reading and writing Standard MIDI Files. Getting Started Add MI

Steffan Andrews 3 Aug 30, 2022
Swift framework for zipping and unzipping files.

Zip A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. Usage Import Zip at the top of the Swift file

Roy Marmelstein 2.3k Dec 30, 2022
Swift framework to connect SMB2/3 shares

AMSMB2 This is small Swift library for iOS, macOS and tvOS which wraps libsmb2 and allows to connect a SMB2/3 share and do file operation. Install Coc

Amir Abbas Mousavian 157 Dec 19, 2022
ZipArchive is a simple utility class for zipping and unzipping files on iOS, macOS and tvOS.

SSZipArchive ZipArchive is a simple utility class for zipping and unzipping files on iOS, macOS and tvOS. Unzip zip files; Unzip password protected zi

ZipArchive 5.2k Jan 2, 2023
A library and tool for interacting with both the local and remote asset caches.

Asset Cache Tool A library and tool for interacting with both the local and remote asset caches. This is based on research I did a few years ago on th

Kenneth Endfinger 20 Dec 23, 2022
A micro-library for creating and observing events.

Signals Signals is a library for creating and observing events. It replaces delegates, actions and NSNotificationCenter with something much more power

Tuomas Artman 454 Dec 21, 2022
Remote network and data debugging for your native iOS app using Chrome Developer Tools

PonyDebugger PonyDebugger is a remote debugging toolset. It is a client library and gateway server combination that uses Chrome Developer Tools on you

Square 5.9k Dec 24, 2022
Xcode-developer-disk-image-all-platforms - A repo which shares all developer disk images for iOS, tvOS, watchOS

Disclaimer: The available resources and files from this repo are uploaded from many contributors. The files are unverified, untested, and could have n

Hai K 253 Dec 21, 2022
Capacitor File Opener. The plugin is able to open a file given the mimeType and the file uri

Capacitor File Opener. The plugin is able to open a file given the mimeType and the file uri. This plugin is similar to cordova-plugin-file-opener2 without installation support.

Capacitor Community 32 Dec 21, 2022
Modern thread-safe and type-safe key-value observing for Swift and Objective-C

Now Archived and Forked PMKVObserver will not be maintained in this repository going forward. Please use, create issues on, and make PRs to the fork o

Postmates Inc. 708 Jun 29, 2022