xcode - NSTimer not firing when NSMenu is open in Swift -


i have timer runs restart alarm once goes off.

alarm = nstimer.scheduledtimerwithtimeinterval(     60 * minutesconstant + secondsconstant,     target:self,     selector: selector("endsession"),     userinfo: nil,     repeats:false) 

its selector function sets mode flag, , calls original function set alarm new minutes , seconds constants, , sends user notification session has restarted.

i have menu item gets updated remaining time

enter image description here

so i've been opening check alarm indeed restart, , notification shows once hits zero. works, when have menu open , gets down 0 stays @ 0:00 , timer doesn't fire until click off menu @ point shows notification , resets timer intended.

how can force timer fire when menu open? it's not big deal don't want user confused session hangs if watch timer go down.

you have add timer main runloop follow:

swift 3

runloop.main.add(alarm, formode: .commonmodes) 

swift 2.x

nsrunloop.mainrunloop().addtimer(alarm, formode: nsrunloopcommonmodes) 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -