I'm new with Swift 2, I never had developed in Apple. Objective C has seemed ugly and you have to write a lot of code, so Swift liked because the syntax is similar to Java and C and here my question:
In Java you can define a class of this way:
new Thread(){
public run(){
// anything
}
}.start();
Then, Swift can do this? And how?
Thank and greetings
Solution
let myThread=NSThread(target: self, selector: "backgroundWork", object: nil)
myThread.start()
}
func backgroundWork(){
for (self.counter=0;self.counter<10;self.counter++){
//self.myLabel.text = String(self.counter) // Not update UI
self.performSelectorOnMainThread( Selector("updateLabel"), withObject: nil, waitUntilDone: false )
sleep(3)
}
}
func updateLabel(){
self.myLabel.text = String(self.counter)
}