Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing variables outside the scope of the eventHandler scope #2

Closed
eonist opened this issue Apr 9, 2016 · 3 comments
Closed

Accessing variables outside the scope of the eventHandler scope #2

eonist opened this issue Apr 9, 2016 · 3 comments

Comments

@eonist
Copy link

eonist commented Apr 9, 2016

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)
    }
})
@eonist
Copy link
Author

eonist commented Apr 9, 2016

I guess my dream of making a FileWatcher being instance based wont work. I can get it working with NSNotificationCenter But then the class becomes useless if i want to make more than one filewatcher.

@eonist
Copy link
Author

eonist commented Apr 9, 2016

My next idea is to use dispatch_get_main_queue to get it to work in an instance based mode.

@eonist
Copy link
Author

eonist commented Apr 10, 2016

Solved it using weak self in the closure

@eonist eonist closed this as completed Apr 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant