├── README.md ├── SwiftFSWatcher.podspec ├── framework └── SwiftFSWatcher.framework.zip └── src └── SwiftFSWatcher ├── .gitignore ├── SwiftFSWatcher.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcbaselines │ └── 4107500C1CB9BC2800EB5B19.xcbaseline │ ├── E52B02C5-0F01-47AF-8CE2-CEF6677CB812.plist │ └── Info.plist ├── SwiftFSWatcher ├── Info.plist ├── SwiftFSWatcher.h └── SwiftFSWatcher.swift └── SwiftFSWatcherTests ├── Info.plist └── SwiftFSWatcherTests.swift /README.md: -------------------------------------------------------------------------------- 1 | # SwiftFSWatcher 2 | A simple easy to use / extend File System watcher using Swift 3 | 4 | Please file any bugs you may encounter in the newer or even the current older version! 5 | 6 | # Example (Swift) 7 | 8 | ```swift 9 | import Cocoa 10 | import SwiftFSWatcher 11 | 12 | class ViewController: NSViewController { 13 | 14 | // NOTE: - Any instance of `SwiftFSWatcher` must be class scoped, like below: 15 | 16 | /* This will not crash your app. */ 17 | let fileWatcher = SwiftFSWatcher(["/var/www/html/", "/home/Downloads/"]) 18 | let anotherWatcher = SwiftFSWatcher() 19 | 20 | override func viewDidLoad() { 21 | super.viewDidLoad() 22 | 23 | /* Using `localWatcher` will crash your app. */ 24 | // let localWatcher = SwiftFSWatcher() 25 | 26 | fileWatcher.watch { changeEvents in 27 | for ev in changeEvents { 28 | print("eventPath: \(ev.eventPath), eventFlag: \(ev.eventFlag), eventId: \(ev.eventId)") 29 | 30 | // check if this event is of a file created 31 | if ev.eventFlag == (kFSEventStreamEventFlagItemIsFile + kFSEventStreamEventFlagItemCreated) { 32 | print("created file at path: \(ev.eventPath)") 33 | } 34 | 35 | } 36 | } 37 | 38 | // setup and listen second watcher events on files only 39 | anotherWatcher.watchingPaths = ["/home/myFile.txt", "/root/bash_session.txt"] 40 | anotherWatcher.watch { changeEvents in 41 | for ev in changeEvents { 42 | print("eventPath: \(ev.eventPath), eventFlag: \(ev.eventFlag), eventId: \(ev.eventId)") 43 | 44 | if ev.eventFlag == (kFSEventStreamEventFlagItemIsFile + kFSEventStreamEventFlagItemInodeMetaMod + kFSEventStreamEventFlagItemModified) { 45 | print("file modified at: \(ev.eventPath)") 46 | } 47 | } 48 | } 49 | } 50 | } 51 | ``` 52 | 53 | # Example (Objective-C) 54 | ```objc 55 | #import "ViewController.h" 56 | #import 57 | 58 | @implementation ViewController 59 | 60 | SwiftFSWatcher * s; 61 | 62 | - (void)viewDidLoad { 63 | [super viewDidLoad]; 64 | 65 | s = [[SwiftFSWatcher alloc] init]; 66 | 67 | s.watchingPaths = [@[@"/path/to/some/folder/", @"/path/to/myFile.txt"] mutableCopy]; 68 | 69 | [s watch:^(NSArray * aa) { 70 | NSLog(@"changed paths: %@", aa); 71 | }]; 72 | } 73 | @end 74 | ``` 75 | 76 | # Installation (two ways) 77 | 78 | + Include `pod 'SwiftFSWatcher'` in your Podfile 79 | + You'll need to add `use_frameworks!` since the framework is built in Swift. 80 | 81 | + Grab the `SwiftFSWatcher.framework` and add it to your project or build the `.framework` yoursleves by downloading this project. 82 | 83 | + Use it in your app 84 | 85 | # Questions? 86 | 87 | Have a question? Feel free to email me. 88 | 89 | # You added a new feature? 90 | 91 | Send it in right now! I can't wait to see what you've done! 92 | 93 | # Found a Bug? 94 | 95 | Oh No! Send in a pull request with the patch (very much appreciated) or just contact me :D 96 | 97 | # License 98 | 99 | [MIT License](http://opensource.org/licenses/MIT) 100 | -------------------------------------------------------------------------------- /SwiftFSWatcher.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | 3 | s.name = "SwiftFSWatcher" 4 | s.version = "1.02-4" 5 | s.summary = "A simple easy to use / extend File System watcher using Swift." 6 | 7 | s.homepage = "https://github.com/gurinderhans/SwiftFSWatcher" 8 | 9 | s.license = { :type => 'MIT', :text => <<-LICENSE 10 | Version 1.0 11 | 12 | Created by Gurinder Hans on 04/10/2016. 13 | Copyright 2016 Gurinder Hans 14 | 15 | This code is distributed under the terms and conditions of the MIT license. 16 | 17 | Permission is hereby granted, free of charge, to any person obtaining a copy 18 | of this software and associated documentation files (the "Software"), to deal 19 | in the Software without restriction, including without limitation the rights 20 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 21 | copies of the Software, and to permit persons to whom the Software is 22 | furnished to do so, subject to the following conditions: 23 | 24 | The above copyright notice and this permission notice shall be included in 25 | all copies or substantial portions of the Software. 26 | 27 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 28 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 29 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 30 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 31 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 32 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 33 | THE SOFTWARE. 34 | LICENSE 35 | } 36 | s.author = { "Gurinder Hans" => "hello@gurinderhans.me" } 37 | s.social_media_url = "http://twitter.com/itsgurinderhans" 38 | 39 | s.platform = :osx 40 | s.osx.deployment_target = '10.9' 41 | 42 | s.source = { :git => "https://github.com/gurinderhans/SwiftFSWatcher.git", :tag => "#{s.version}" } 43 | 44 | s.source_files = "Classes", "src/SwiftFSWatcher/SwiftFSWatcher/SwiftFSWatcher.{h,swift}" 45 | 46 | end 47 | -------------------------------------------------------------------------------- /framework/SwiftFSWatcher.framework.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gurinderhans/SwiftFSWatcher/bc19c750bc1a80448542bab9b56a7405e334d103/framework/SwiftFSWatcher.framework.zip -------------------------------------------------------------------------------- /src/SwiftFSWatcher/.gitignore: -------------------------------------------------------------------------------- 1 | ### Xcode ### 2 | # Xcode 3 | # 4 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 5 | 6 | ## Build generated 7 | build/ 8 | DerivedData/ 9 | 10 | ## Various settings 11 | *.pbxuser 12 | !default.pbxuser 13 | *.mode1v3 14 | !default.mode1v3 15 | *.mode2v3 16 | !default.mode2v3 17 | *.perspectivev3 18 | !default.perspectivev3 19 | xcuserdata/ 20 | 21 | ## Other 22 | *.moved-aside 23 | *.xccheckout 24 | *.xcscmblueprint 25 | -------------------------------------------------------------------------------- /src/SwiftFSWatcher/SwiftFSWatcher.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 410750071CB9BC2800EB5B19 /* SwiftFSWatcher.h in Headers */ = {isa = PBXBuildFile; fileRef = 410750061CB9BC2800EB5B19 /* SwiftFSWatcher.h */; settings = {ATTRIBUTES = (Public, ); }; }; 11 | 4107500E1CB9BC2800EB5B19 /* SwiftFSWatcher.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 410750031CB9BC2800EB5B19 /* SwiftFSWatcher.framework */; }; 12 | 410750131CB9BC2800EB5B19 /* SwiftFSWatcherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 410750121CB9BC2800EB5B19 /* SwiftFSWatcherTests.swift */; }; 13 | 4107501E1CB9BD9D00EB5B19 /* SwiftFSWatcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4107501D1CB9BD9D00EB5B19 /* SwiftFSWatcher.swift */; }; 14 | /* End PBXBuildFile section */ 15 | 16 | /* Begin PBXContainerItemProxy section */ 17 | 4107500F1CB9BC2800EB5B19 /* PBXContainerItemProxy */ = { 18 | isa = PBXContainerItemProxy; 19 | containerPortal = 41074FFA1CB9BC2800EB5B19 /* Project object */; 20 | proxyType = 1; 21 | remoteGlobalIDString = 410750021CB9BC2800EB5B19; 22 | remoteInfo = SwiftFSWatcher; 23 | }; 24 | /* End PBXContainerItemProxy section */ 25 | 26 | /* Begin PBXFileReference section */ 27 | 410750031CB9BC2800EB5B19 /* SwiftFSWatcher.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftFSWatcher.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 28 | 410750061CB9BC2800EB5B19 /* SwiftFSWatcher.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftFSWatcher.h; sourceTree = ""; }; 29 | 410750081CB9BC2800EB5B19 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 4107500D1CB9BC2800EB5B19 /* SwiftFSWatcherTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftFSWatcherTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | 410750121CB9BC2800EB5B19 /* SwiftFSWatcherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftFSWatcherTests.swift; sourceTree = ""; }; 32 | 410750141CB9BC2800EB5B19 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 33 | 4107501D1CB9BD9D00EB5B19 /* SwiftFSWatcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftFSWatcher.swift; sourceTree = ""; }; 34 | /* End PBXFileReference section */ 35 | 36 | /* Begin PBXFrameworksBuildPhase section */ 37 | 41074FFF1CB9BC2800EB5B19 /* Frameworks */ = { 38 | isa = PBXFrameworksBuildPhase; 39 | buildActionMask = 2147483647; 40 | files = ( 41 | ); 42 | runOnlyForDeploymentPostprocessing = 0; 43 | }; 44 | 4107500A1CB9BC2800EB5B19 /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | 4107500E1CB9BC2800EB5B19 /* SwiftFSWatcher.framework in Frameworks */, 49 | ); 50 | runOnlyForDeploymentPostprocessing = 0; 51 | }; 52 | /* End PBXFrameworksBuildPhase section */ 53 | 54 | /* Begin PBXGroup section */ 55 | 41074FF91CB9BC2800EB5B19 = { 56 | isa = PBXGroup; 57 | children = ( 58 | 410750051CB9BC2800EB5B19 /* SwiftFSWatcher */, 59 | 410750111CB9BC2800EB5B19 /* SwiftFSWatcherTests */, 60 | 410750041CB9BC2800EB5B19 /* Products */, 61 | ); 62 | sourceTree = ""; 63 | }; 64 | 410750041CB9BC2800EB5B19 /* Products */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 410750031CB9BC2800EB5B19 /* SwiftFSWatcher.framework */, 68 | 4107500D1CB9BC2800EB5B19 /* SwiftFSWatcherTests.xctest */, 69 | ); 70 | name = Products; 71 | sourceTree = ""; 72 | }; 73 | 410750051CB9BC2800EB5B19 /* SwiftFSWatcher */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | 410750061CB9BC2800EB5B19 /* SwiftFSWatcher.h */, 77 | 410750081CB9BC2800EB5B19 /* Info.plist */, 78 | 4107501D1CB9BD9D00EB5B19 /* SwiftFSWatcher.swift */, 79 | ); 80 | path = SwiftFSWatcher; 81 | sourceTree = ""; 82 | }; 83 | 410750111CB9BC2800EB5B19 /* SwiftFSWatcherTests */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | 410750121CB9BC2800EB5B19 /* SwiftFSWatcherTests.swift */, 87 | 410750141CB9BC2800EB5B19 /* Info.plist */, 88 | ); 89 | path = SwiftFSWatcherTests; 90 | sourceTree = ""; 91 | }; 92 | /* End PBXGroup section */ 93 | 94 | /* Begin PBXHeadersBuildPhase section */ 95 | 410750001CB9BC2800EB5B19 /* Headers */ = { 96 | isa = PBXHeadersBuildPhase; 97 | buildActionMask = 2147483647; 98 | files = ( 99 | 410750071CB9BC2800EB5B19 /* SwiftFSWatcher.h in Headers */, 100 | ); 101 | runOnlyForDeploymentPostprocessing = 0; 102 | }; 103 | /* End PBXHeadersBuildPhase section */ 104 | 105 | /* Begin PBXNativeTarget section */ 106 | 410750021CB9BC2800EB5B19 /* SwiftFSWatcher */ = { 107 | isa = PBXNativeTarget; 108 | buildConfigurationList = 410750171CB9BC2800EB5B19 /* Build configuration list for PBXNativeTarget "SwiftFSWatcher" */; 109 | buildPhases = ( 110 | 41074FFE1CB9BC2800EB5B19 /* Sources */, 111 | 41074FFF1CB9BC2800EB5B19 /* Frameworks */, 112 | 410750001CB9BC2800EB5B19 /* Headers */, 113 | 410750011CB9BC2800EB5B19 /* Resources */, 114 | ); 115 | buildRules = ( 116 | ); 117 | dependencies = ( 118 | ); 119 | name = SwiftFSWatcher; 120 | productName = SwiftFSWatcher; 121 | productReference = 410750031CB9BC2800EB5B19 /* SwiftFSWatcher.framework */; 122 | productType = "com.apple.product-type.framework"; 123 | }; 124 | 4107500C1CB9BC2800EB5B19 /* SwiftFSWatcherTests */ = { 125 | isa = PBXNativeTarget; 126 | buildConfigurationList = 4107501A1CB9BC2800EB5B19 /* Build configuration list for PBXNativeTarget "SwiftFSWatcherTests" */; 127 | buildPhases = ( 128 | 410750091CB9BC2800EB5B19 /* Sources */, 129 | 4107500A1CB9BC2800EB5B19 /* Frameworks */, 130 | 4107500B1CB9BC2800EB5B19 /* Resources */, 131 | ); 132 | buildRules = ( 133 | ); 134 | dependencies = ( 135 | 410750101CB9BC2800EB5B19 /* PBXTargetDependency */, 136 | ); 137 | name = SwiftFSWatcherTests; 138 | productName = SwiftFSWatcherTests; 139 | productReference = 4107500D1CB9BC2800EB5B19 /* SwiftFSWatcherTests.xctest */; 140 | productType = "com.apple.product-type.bundle.unit-test"; 141 | }; 142 | /* End PBXNativeTarget section */ 143 | 144 | /* Begin PBXProject section */ 145 | 41074FFA1CB9BC2800EB5B19 /* Project object */ = { 146 | isa = PBXProject; 147 | attributes = { 148 | LastSwiftUpdateCheck = 0730; 149 | LastUpgradeCheck = 0820; 150 | ORGANIZATIONNAME = "Gurinder Hans"; 151 | TargetAttributes = { 152 | 410750021CB9BC2800EB5B19 = { 153 | CreatedOnToolsVersion = 7.3; 154 | LastSwiftMigration = 0900; 155 | }; 156 | 4107500C1CB9BC2800EB5B19 = { 157 | CreatedOnToolsVersion = 7.3; 158 | LastSwiftMigration = 0900; 159 | }; 160 | }; 161 | }; 162 | buildConfigurationList = 41074FFD1CB9BC2800EB5B19 /* Build configuration list for PBXProject "SwiftFSWatcher" */; 163 | compatibilityVersion = "Xcode 3.2"; 164 | developmentRegion = English; 165 | hasScannedForEncodings = 0; 166 | knownRegions = ( 167 | en, 168 | ); 169 | mainGroup = 41074FF91CB9BC2800EB5B19; 170 | productRefGroup = 410750041CB9BC2800EB5B19 /* Products */; 171 | projectDirPath = ""; 172 | projectRoot = ""; 173 | targets = ( 174 | 410750021CB9BC2800EB5B19 /* SwiftFSWatcher */, 175 | 4107500C1CB9BC2800EB5B19 /* SwiftFSWatcherTests */, 176 | ); 177 | }; 178 | /* End PBXProject section */ 179 | 180 | /* Begin PBXResourcesBuildPhase section */ 181 | 410750011CB9BC2800EB5B19 /* Resources */ = { 182 | isa = PBXResourcesBuildPhase; 183 | buildActionMask = 2147483647; 184 | files = ( 185 | ); 186 | runOnlyForDeploymentPostprocessing = 0; 187 | }; 188 | 4107500B1CB9BC2800EB5B19 /* Resources */ = { 189 | isa = PBXResourcesBuildPhase; 190 | buildActionMask = 2147483647; 191 | files = ( 192 | ); 193 | runOnlyForDeploymentPostprocessing = 0; 194 | }; 195 | /* End PBXResourcesBuildPhase section */ 196 | 197 | /* Begin PBXSourcesBuildPhase section */ 198 | 41074FFE1CB9BC2800EB5B19 /* Sources */ = { 199 | isa = PBXSourcesBuildPhase; 200 | buildActionMask = 2147483647; 201 | files = ( 202 | 4107501E1CB9BD9D00EB5B19 /* SwiftFSWatcher.swift in Sources */, 203 | ); 204 | runOnlyForDeploymentPostprocessing = 0; 205 | }; 206 | 410750091CB9BC2800EB5B19 /* Sources */ = { 207 | isa = PBXSourcesBuildPhase; 208 | buildActionMask = 2147483647; 209 | files = ( 210 | 410750131CB9BC2800EB5B19 /* SwiftFSWatcherTests.swift in Sources */, 211 | ); 212 | runOnlyForDeploymentPostprocessing = 0; 213 | }; 214 | /* End PBXSourcesBuildPhase section */ 215 | 216 | /* Begin PBXTargetDependency section */ 217 | 410750101CB9BC2800EB5B19 /* PBXTargetDependency */ = { 218 | isa = PBXTargetDependency; 219 | target = 410750021CB9BC2800EB5B19 /* SwiftFSWatcher */; 220 | targetProxy = 4107500F1CB9BC2800EB5B19 /* PBXContainerItemProxy */; 221 | }; 222 | /* End PBXTargetDependency section */ 223 | 224 | /* Begin XCBuildConfiguration section */ 225 | 410750151CB9BC2800EB5B19 /* Debug */ = { 226 | isa = XCBuildConfiguration; 227 | buildSettings = { 228 | ALWAYS_SEARCH_USER_PATHS = NO; 229 | CLANG_ANALYZER_NONNULL = YES; 230 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 231 | CLANG_CXX_LIBRARY = "libc++"; 232 | CLANG_ENABLE_MODULES = YES; 233 | CLANG_ENABLE_OBJC_ARC = YES; 234 | CLANG_WARN_BOOL_CONVERSION = YES; 235 | CLANG_WARN_CONSTANT_CONVERSION = YES; 236 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 237 | CLANG_WARN_EMPTY_BODY = YES; 238 | CLANG_WARN_ENUM_CONVERSION = YES; 239 | CLANG_WARN_INFINITE_RECURSION = YES; 240 | CLANG_WARN_INT_CONVERSION = YES; 241 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 242 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 243 | CLANG_WARN_UNREACHABLE_CODE = YES; 244 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 245 | CODE_SIGN_IDENTITY = "-"; 246 | COPY_PHASE_STRIP = NO; 247 | CURRENT_PROJECT_VERSION = 1; 248 | DEBUG_INFORMATION_FORMAT = dwarf; 249 | ENABLE_STRICT_OBJC_MSGSEND = YES; 250 | ENABLE_TESTABILITY = YES; 251 | GCC_C_LANGUAGE_STANDARD = gnu99; 252 | GCC_DYNAMIC_NO_PIC = NO; 253 | GCC_NO_COMMON_BLOCKS = YES; 254 | GCC_OPTIMIZATION_LEVEL = 0; 255 | GCC_PREPROCESSOR_DEFINITIONS = ( 256 | "DEBUG=1", 257 | "$(inherited)", 258 | ); 259 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 260 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 261 | GCC_WARN_UNDECLARED_SELECTOR = YES; 262 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 263 | GCC_WARN_UNUSED_FUNCTION = YES; 264 | GCC_WARN_UNUSED_VARIABLE = YES; 265 | MACOSX_DEPLOYMENT_TARGET = 10.11; 266 | MTL_ENABLE_DEBUG_INFO = YES; 267 | ONLY_ACTIVE_ARCH = YES; 268 | SDKROOT = macosx; 269 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 270 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 271 | VERSIONING_SYSTEM = "apple-generic"; 272 | VERSION_INFO_PREFIX = ""; 273 | }; 274 | name = Debug; 275 | }; 276 | 410750161CB9BC2800EB5B19 /* Release */ = { 277 | isa = XCBuildConfiguration; 278 | buildSettings = { 279 | ALWAYS_SEARCH_USER_PATHS = NO; 280 | CLANG_ANALYZER_NONNULL = YES; 281 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 282 | CLANG_CXX_LIBRARY = "libc++"; 283 | CLANG_ENABLE_MODULES = YES; 284 | CLANG_ENABLE_OBJC_ARC = YES; 285 | CLANG_WARN_BOOL_CONVERSION = YES; 286 | CLANG_WARN_CONSTANT_CONVERSION = YES; 287 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 288 | CLANG_WARN_EMPTY_BODY = YES; 289 | CLANG_WARN_ENUM_CONVERSION = YES; 290 | CLANG_WARN_INFINITE_RECURSION = YES; 291 | CLANG_WARN_INT_CONVERSION = YES; 292 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 293 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 294 | CLANG_WARN_UNREACHABLE_CODE = YES; 295 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 296 | CODE_SIGN_IDENTITY = "-"; 297 | COPY_PHASE_STRIP = NO; 298 | CURRENT_PROJECT_VERSION = 1; 299 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 300 | ENABLE_NS_ASSERTIONS = NO; 301 | ENABLE_STRICT_OBJC_MSGSEND = YES; 302 | GCC_C_LANGUAGE_STANDARD = gnu99; 303 | GCC_NO_COMMON_BLOCKS = YES; 304 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 305 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 306 | GCC_WARN_UNDECLARED_SELECTOR = YES; 307 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 308 | GCC_WARN_UNUSED_FUNCTION = YES; 309 | GCC_WARN_UNUSED_VARIABLE = YES; 310 | MACOSX_DEPLOYMENT_TARGET = 10.11; 311 | MTL_ENABLE_DEBUG_INFO = NO; 312 | SDKROOT = macosx; 313 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 314 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 315 | VERSIONING_SYSTEM = "apple-generic"; 316 | VERSION_INFO_PREFIX = ""; 317 | }; 318 | name = Release; 319 | }; 320 | 410750181CB9BC2800EB5B19 /* Debug */ = { 321 | isa = XCBuildConfiguration; 322 | buildSettings = { 323 | CLANG_ENABLE_MODULES = YES; 324 | CODE_SIGN_IDENTITY = ""; 325 | COMBINE_HIDPI_IMAGES = YES; 326 | DEFINES_MODULE = YES; 327 | DYLIB_COMPATIBILITY_VERSION = 1; 328 | DYLIB_CURRENT_VERSION = 1; 329 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 330 | FRAMEWORK_VERSION = A; 331 | INFOPLIST_FILE = SwiftFSWatcher/Info.plist; 332 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 333 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; 334 | PRODUCT_BUNDLE_IDENTIFIER = me.gurinderhans.SwiftFSWatcher; 335 | PRODUCT_NAME = "$(TARGET_NAME)"; 336 | SKIP_INSTALL = YES; 337 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 338 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 339 | SWIFT_VERSION = 4.0; 340 | }; 341 | name = Debug; 342 | }; 343 | 410750191CB9BC2800EB5B19 /* Release */ = { 344 | isa = XCBuildConfiguration; 345 | buildSettings = { 346 | CLANG_ENABLE_MODULES = YES; 347 | CODE_SIGN_IDENTITY = ""; 348 | COMBINE_HIDPI_IMAGES = YES; 349 | DEFINES_MODULE = YES; 350 | DYLIB_COMPATIBILITY_VERSION = 1; 351 | DYLIB_CURRENT_VERSION = 1; 352 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 353 | FRAMEWORK_VERSION = A; 354 | INFOPLIST_FILE = SwiftFSWatcher/Info.plist; 355 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 356 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; 357 | PRODUCT_BUNDLE_IDENTIFIER = me.gurinderhans.SwiftFSWatcher; 358 | PRODUCT_NAME = "$(TARGET_NAME)"; 359 | SKIP_INSTALL = YES; 360 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 361 | SWIFT_VERSION = 4.0; 362 | }; 363 | name = Release; 364 | }; 365 | 4107501B1CB9BC2800EB5B19 /* Debug */ = { 366 | isa = XCBuildConfiguration; 367 | buildSettings = { 368 | COMBINE_HIDPI_IMAGES = YES; 369 | INFOPLIST_FILE = SwiftFSWatcherTests/Info.plist; 370 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 371 | PRODUCT_BUNDLE_IDENTIFIER = me.gurinderhans.SwiftFSWatcherTests; 372 | PRODUCT_NAME = "$(TARGET_NAME)"; 373 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 374 | SWIFT_VERSION = 4.0; 375 | }; 376 | name = Debug; 377 | }; 378 | 4107501C1CB9BC2800EB5B19 /* Release */ = { 379 | isa = XCBuildConfiguration; 380 | buildSettings = { 381 | COMBINE_HIDPI_IMAGES = YES; 382 | INFOPLIST_FILE = SwiftFSWatcherTests/Info.plist; 383 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 384 | PRODUCT_BUNDLE_IDENTIFIER = me.gurinderhans.SwiftFSWatcherTests; 385 | PRODUCT_NAME = "$(TARGET_NAME)"; 386 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 387 | SWIFT_VERSION = 4.0; 388 | }; 389 | name = Release; 390 | }; 391 | /* End XCBuildConfiguration section */ 392 | 393 | /* Begin XCConfigurationList section */ 394 | 41074FFD1CB9BC2800EB5B19 /* Build configuration list for PBXProject "SwiftFSWatcher" */ = { 395 | isa = XCConfigurationList; 396 | buildConfigurations = ( 397 | 410750151CB9BC2800EB5B19 /* Debug */, 398 | 410750161CB9BC2800EB5B19 /* Release */, 399 | ); 400 | defaultConfigurationIsVisible = 0; 401 | defaultConfigurationName = Release; 402 | }; 403 | 410750171CB9BC2800EB5B19 /* Build configuration list for PBXNativeTarget "SwiftFSWatcher" */ = { 404 | isa = XCConfigurationList; 405 | buildConfigurations = ( 406 | 410750181CB9BC2800EB5B19 /* Debug */, 407 | 410750191CB9BC2800EB5B19 /* Release */, 408 | ); 409 | defaultConfigurationIsVisible = 0; 410 | defaultConfigurationName = Release; 411 | }; 412 | 4107501A1CB9BC2800EB5B19 /* Build configuration list for PBXNativeTarget "SwiftFSWatcherTests" */ = { 413 | isa = XCConfigurationList; 414 | buildConfigurations = ( 415 | 4107501B1CB9BC2800EB5B19 /* Debug */, 416 | 4107501C1CB9BC2800EB5B19 /* Release */, 417 | ); 418 | defaultConfigurationIsVisible = 0; 419 | defaultConfigurationName = Release; 420 | }; 421 | /* End XCConfigurationList section */ 422 | }; 423 | rootObject = 41074FFA1CB9BC2800EB5B19 /* Project object */; 424 | } 425 | -------------------------------------------------------------------------------- /src/SwiftFSWatcher/SwiftFSWatcher.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/SwiftFSWatcher/SwiftFSWatcher.xcodeproj/xcshareddata/xcbaselines/4107500C1CB9BC2800EB5B19.xcbaseline/E52B02C5-0F01-47AF-8CE2-CEF6677CB812.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | classNames 6 | 7 | SwiftFSWatcherTests 8 | 9 | testPerformanceExample() 10 | 11 | com.apple.XCTPerformanceMetric_WallClockTime 12 | 13 | baselineAverage 14 | 0 15 | baselineIntegrationDisplayName 16 | Local Baseline 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/SwiftFSWatcher/SwiftFSWatcher.xcodeproj/xcshareddata/xcbaselines/4107500C1CB9BC2800EB5B19.xcbaseline/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | runDestinationsByUUID 6 | 7 | E52B02C5-0F01-47AF-8CE2-CEF6677CB812 8 | 9 | localComputer 10 | 11 | busSpeedInMHz 12 | 100 13 | cpuCount 14 | 1 15 | cpuKind 16 | Intel Core i7 17 | cpuSpeedInMHz 18 | 1700 19 | logicalCPUCoresPerPackage 20 | 4 21 | modelCode 22 | MacBookAir6,2 23 | physicalCPUCoresPerPackage 24 | 2 25 | platformIdentifier 26 | com.apple.platform.macosx 27 | 28 | targetArchitecture 29 | x86_64 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/SwiftFSWatcher/SwiftFSWatcher/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSHumanReadableCopyright 24 | Copyright © 2016 Gurinder Hans. All rights reserved. 25 | NSPrincipalClass 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/SwiftFSWatcher/SwiftFSWatcher/SwiftFSWatcher.h: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftFSWatcher.h 3 | // SwiftFSWatcher 4 | // 5 | // Created by Gurinder Hans on 4/9/16. 6 | // Copyright © 2016 Gurinder Hans. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for SwiftFSWatcher. 12 | FOUNDATION_EXPORT double SwiftFSWatcherVersionNumber; 13 | 14 | //! Project version string for SwiftFSWatcher. 15 | FOUNDATION_EXPORT const unsigned char SwiftFSWatcherVersionString[]; -------------------------------------------------------------------------------- /src/SwiftFSWatcher/SwiftFSWatcher/SwiftFSWatcher.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftFSWatcher.swift 3 | // SwiftFSWatcher 4 | // 5 | // Created by Gurinder Hans on 4/9/16. 6 | // Copyright © 2016 Gurinder Hans. All rights reserved. 7 | // 8 | 9 | @objc open class SwiftFSWatcher : NSObject { 10 | 11 | var stream: FSEventStreamRef? 12 | 13 | var onChangeCallback: (([FileEvent]) -> Void)? 14 | 15 | open var watchingPaths: [String]? { 16 | didSet { 17 | guard stream != nil else { 18 | return 19 | } 20 | 21 | pause() 22 | stream = nil 23 | watch(onChangeCallback) 24 | } 25 | } 26 | 27 | 28 | // MARK: - Init methods 29 | 30 | public override init() { 31 | // Default init 32 | super.init() 33 | } 34 | 35 | public convenience init(_ paths: [String]) { 36 | self.init() 37 | self.watchingPaths = paths 38 | } 39 | 40 | // MARK: - API public methods 41 | 42 | open func watch(_ changeCb: (([FileEvent]) -> Void)?) { 43 | guard let paths = watchingPaths else { 44 | return 45 | } 46 | 47 | guard stream == nil else { 48 | return 49 | } 50 | 51 | onChangeCallback = changeCb 52 | 53 | var context = FSEventStreamContext(version: 0, info: UnsafeMutableRawPointer(mutating: Unmanaged.passUnretained(self).toOpaque()), retain: nil, release: nil, copyDescription: nil) 54 | stream = FSEventStreamCreate(kCFAllocatorDefault, innerEventCallback, &context, paths as CFArray, FSEventStreamEventId(kFSEventStreamEventIdSinceNow), 0, UInt32(kFSEventStreamCreateFlagUseCFTypes | kFSEventStreamCreateFlagFileEvents)) 55 | FSEventStreamScheduleWithRunLoop(stream!, RunLoop.current.getCFRunLoop(), CFRunLoopMode.defaultMode.rawValue) 56 | FSEventStreamStart(stream!) 57 | } 58 | 59 | open func resume() { 60 | guard stream != nil else { 61 | return 62 | } 63 | 64 | FSEventStreamStart(stream!) 65 | } 66 | 67 | open func pause() { 68 | guard stream != nil else { 69 | return 70 | } 71 | 72 | FSEventStreamStop(stream!) 73 | } 74 | 75 | // MARK: - [Private] Closure passed into `FSEventStream` and is called on new file event 76 | 77 | fileprivate let innerEventCallback: FSEventStreamCallback = { (stream, contextInfo, numEvents, eventPaths, eventFlags, eventIds) in 78 | 79 | let fsWatcher: SwiftFSWatcher = unsafeBitCast(contextInfo, to: SwiftFSWatcher.self) 80 | let paths = unsafeBitCast(eventPaths, to: NSArray.self) as! [String] 81 | 82 | var fileEvents = [FileEvent]() 83 | for i in 0.. 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/SwiftFSWatcher/SwiftFSWatcherTests/SwiftFSWatcherTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftFSWatcherTests.swift 3 | // SwiftFSWatcherTests 4 | // 5 | // Created by Gurinder Hans on 4/9/16. 6 | // Copyright © 2016 Gurinder Hans. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import SwiftFSWatcher 11 | 12 | class SwiftFSWatcherTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | } 30 | --------------------------------------------------------------------------------