So guys, my problem is that i can't work with timers while i am using gui. My timer is in ViewController and code:
DispatchQueue.main.async {
Timer.scheduledTimer(timeInterval: 1, target: self.songView, selector: #selector(self.songView.update), userInfo: nil, repeats: true)
}
I also tried in outside in dispatchqueue. However, there is a songview and it's update code looks like:
func update(){
DispatchQueue.main.async(execute: {
let theState = self.executeAppleScript(args: self.playerStateArgs, waitReturn: true)
let songName = self.executeAppleScript(args: self.songNameArgs, waitReturn: true)
let bandName = self.executeAppleScript(args: self.bandNameArgs, waitReturn: true)
let artworkUrl = self.executeAppleScript(args: self.artworkArgs, waitReturn: true)
self.songField.stringValue = songName
self.bandField.stringValue = bandName
let url: URL = URL.init(string: artworkUrl)!
self.albumCoverView.image = NSImage.init(contentsOf: url)
NSLog("\(songName)")
})
}
I tried the code outside of the Dispatch queue as well. Non of the combination works for me. Timer works and update function prints the song name every second but when i open the app(menu bar app) gui, update function stops and no Log operation happens. I tried so many things and looked all of the issues here. Unfortunately non of them helped me. Thanks in advance
Edit: While gui is off:
While gui is on:
While off, timer is working. While on, it is not.