I tried output to STDOUT every second by using NSTimer
.
I wrote the following code and saved it as sample.swift.
#!/usr/bin/swift
import AppKit
class Foo : NSObject {
override init() {
super.init()
NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "bar", userInfo: nil, repeats: true)
}
func bar() {
print("buz")
}
}
let h = Foo()
// Output successful
// while true {
// print("Foo!")
// }
NSRunLoop.mainRunLoop().run()
Then, I executed the following command and can see buz
.
okada@iyokan$ ./sample.swift
buz
buz
buz
buz
So, I executed the following command but I cannot see any buz
.
okada@iyokan$ ./sample.swift > sample.log # wait 5 seconds
okada@iyokan$ cat sample.log
okada@iyokan$
By the way, I tried while loop version (activated comment out the above code) then I could get buz
by two procedures.
Why I could not get any buz
?
Please teach me.