ios - How to better structure the functions in this script so that it will continue looping without a crash? -
my program update time each second, , using core graphics hours, minutes , seconds drawn out using shapes in uiview
created in storyboard. when have script set in xcode, @ibdesignable
aspect updates appropriate hour time in storyboard. below uiview
subclass associated uiview
in storyboard.
import uikit @ibdesignable class clock: uiview { func updatetime() -> (hour:int, minute:int, second:int) { var date:nsdate = nsdate() var calendar:nscalendar = nscalendar.currentcalendar() var components:nsdatecomponents = calendar.components(nscalendarunit.calendarunithour | nscalendarunit.calendarunitminute | nscalendarunit.calendarunitsecond, fromdate: date) var hour = components.hour var minute = components.minute var second = components.second setneedsdisplay() return (hour, minute, second) } var timer = nstimer.scheduledtimerwithtimeinterval(0.1, target: self, selector: "updatetime", userinfo: nil, repeats: true) override func drawrect(rect: cgrect) { var hour = updatetime(hour) switch hour { case 0: clockstylekit.drawcanvas0() case 01, 13: clockstylekit.drawcanvas0() clockstylekit.drawcanvas01() case 02, 14: clockstylekit.drawcanvas0() clockstylekit.drawcanvas01() clockstylekit.drawcanvas02() } }
when crashes, culprit line:
var hour = updatetime()
it throws error says
variable used within own initial value.
any ideas? how can better structure continue updating time?
Comments
Post a Comment