Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Lukas Smith
4,026 PointsHow can i do a flash light/torch in SOS signal
i want after click on button, blink led/torch in SOS signal. For now i have a simple blink led. But what should i do? use NSTimer as switch or Thread ? this is my simple code:
class Sos {
var timer1 = NSTimer()
var timer2 = NSTimer()
var volume: Float = 0.1
let flashLight = FlashLight()
func start() {
self.timer1 = NSTimer.scheduledTimerWithTimeInterval(0.2,
target: self,
selector: Selector("switchON"),
userInfo: nil,
repeats: true)
self.timer2 = NSTimer.scheduledTimerWithTimeInterval(0.4,
target: self,
selector: Selector("switchOFF"),
userInfo: nil,
repeats: true)
}
func stop() {
timer1.invalidate()
timer2.invalidate()
flashLight.switchOFF()
}
@objc func switchON() {
flashLight.switchON(self.volume)
}
@objc func switchOFF() {
flashLight.switchOFF()
}
deinit {
self.timer1.invalidate()
self.timer2.invalidate()
}
}