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

Timers not work #3

Open
bootchk opened this issue Dec 29, 2017 · 3 comments
Open

Timers not work #3

bootchk opened this issue Dec 29, 2017 · 3 comments

Comments

@bootchk
Copy link

bootchk commented Dec 29, 2017

The pauseScan and resumeScan timers never fire. At least they never print. Xcode 7.3.1, iOS 9.3.5

@jsoncylu
Copy link

They are supposed to be scheduledTimers, at least as of Swift 3. I would replace the Timer lines to match this:

_ = Timer.scheduledTimer(timeInterval: timerScanInterval, target: self, selector: #selector(pauseScan), userInfo: nil, repeats: false) centralManager.scanForPeripherals(withServices: nil, options: nil)

jsoncylu added a commit to jsoncylu/ZeroToBLE-Part2-Swift that referenced this issue Jan 23, 2018
@bootchk
Copy link
Author

bootchk commented Jan 24, 2018

I am no expert in Swift but ... I assigned the result to a global "timer" of type NSTimer. All I can say is: it worked for me. The construct " _ = " confuses me with regard to whether an object was created and who owns it and when it might be garbage collected. Especially with regard to a timer object: I imagine it means that that timer will exist, owned by the OS, will fire and then go out of existence? But again, seems a little unnatural to me.

@jsoncylu
Copy link

jsoncylu commented Jan 24, 2018

Yes, it is odd to see it assigned to a "_". With Swift timers, one should call .invalidate()to remove it from the run loop.

Edit: actually since I have made it a "scheduledTimer" that doesn't repeat, it automatically deallocates itself once it is fired.

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

2 participants