TimerEngine

class TimerEngine : NSObject, Sequence, LGV_Timer_StateDelegate

This class is the heart of the timer. It contains the timer state, settings, and stored prefs for all the timers.

  • We increment by tenths of a second.

    Declaration

    Swift

    static let timerInterval: TimeInterval
  • Each tick is 1 second.

    Declaration

    Swift

    static let timerTickInterval: TimeInterval
  • The alarm repeats every second.

    Declaration

    Swift

    static let timerAlarmInterval: TimeInterval
  • This contains our color theme palette.

    Declaration

    Swift

    private static let _sviewBundleName: String
  • This is the key for the app status prefs used by this app.

    Declaration

    Swift

    private static let _appStatePrefsKey: String
  • This is true, if the timer is ticking (running).

    Declaration

    Swift

    private var _timerTicking: Bool
  • The time of the first tick

    Declaration

    Swift

    private var _firstTick: TimeInterval
  • The number of times the alarm has rung.

    Declaration

    Swift

    private var _alarmCount: Int
  • These are the keys we use for our timer prefs dictionary.

    See more

    Declaration

    Swift

    enum TimerPrefKeys : String
  • This will contain the UILabels that are used for the color theme.

    Declaration

    Swift

    private var _colorLabelArray: [UILabel]
  • This is any delegate for this engine. It is a weak reference, in order to inhibit reference loops.

    Declaration

    Swift

    weak var delegate: TimerEngineDelegate!
  • This is the current application state. It is the heart of the timer.

    Declaration

    Swift

    var appState: LGV_Timer_State!
  • This is the current selected timer.

    Declaration

    Swift

    var timer: Timer!
  • This aggregates our available sounds.

    Declaration

    Swift

    var soundSelection: [String]
  • This is the URI to the selected tick sound.

    Declaration

    Swift

    var tickURI: String
  • This is an ephemeral semaphore (yuck) that tells the timer to auto-start after being selected. We use this for cascading timers.

    Declaration

    Swift

    var autoStartNextSelectedTimer: Bool
  • This simply returns true, if a timer is currently selected.

    Declaration

    Swift

    var timerSelected: Bool { get }
  • This returns the currently selected timer (or nil, if no timer is selected).

    Declaration

    Swift

    var selectedTimer: TimerSettingTuple! { get }
  • This returns (or changes) the 0-based index of the selected timer. It will be nil if the timer index is out of range.

    Declaration

    Swift

    var selectedTimerIndex: Int! { get set }
  • This returns the UID of the selected timer object.

    Declaration

    Swift

    var selectedTimerUID: String { get set }
  • This returns true, if we have no timers (We should always have at least one, but belt and suspenders).

    Declaration

    Swift

    var isEmpty: Bool { get }
  • This returns the array of timer objects.

    Declaration

    Swift

    var timers: [TimerSettingTuple] { get set }
  • This returns how many timers we have.

    Declaration

    Swift

    var count: Int { get }
  • This return true, if we currently have a ticking timer.

    Declaration

    Swift

    var timerActive: Bool { get set }
  • This returns the actual elapsed time (in a standard interval) since the timer started.

    Declaration

    Swift

    var actualTimeSinceStart: TimeInterval { get }
  • Returns the color palettes.

    Declaration

    Swift

    var colorLabelArray: [UILabel] { get }
  • We declare this private to keep the class from being initialized without a delegate.

    Declaration

    Swift

    private override init()
  • We instantiate this with a delegate -always

    Declaration

    Swift

    init(delegate: TimerEngineDelegate)

    Parameters

    delegate

    The delegate object.

  • We make sure we clean up after ourselves.

    Declaration

    Swift

    deinit
  • This method loads the main prefs into our instance storage.

    NOTE: This will overwrite any unsaved changes to the current _loadedPrefs property.

    Declaration

    Swift

    private func _loadPrefs()
  • Returns the color for the indexed color theme.

    Declaration

    Swift

    func getIndexedColorThemeColor(_ index: Int) -> UIColor
  • This is a factory for creating a new timer object.

    Declaration

    Swift

    func createNewTimer() -> TimerSettingTuple

    Return Value

    a new timer object, instantiated with a zero time, and default characteristics.

  • This method simply saves the main preferences Dictionary into the standard user defaults.

    Declaration

    Swift

    func savePrefs()
  • Just what it says on the tin. Does nothing if no timer is selected.

    Declaration

    Swift

    func pauseTimer()
  • This will either start, or continue, the selected timer. Does nothing if no timer is selected.

    Declaration

    Swift

    func continueTimer()
  • This starts a selected timer from scratch. Does nothing if no timer is selected.

    Declaration

    Swift

    func startTimer()
  • Stops a running selected timer. Does nothing if no timer is selected.

    Declaration

    Swift

    func stopTimer()
  • This resets the selected timer, and returns it to paused mode. Does nothing if no timer is selected.

    Declaration

    Swift

    func resetTimer()
  • This forces a timer to finish, and enter alarm mode. Does nothing if no timer is selected.

    Declaration

    Swift

    func endTimer()
  • Called when the timer status changes

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, didUpdateTimerStatus: TimerSettingTuple, from: TimerStatus)

    Parameters

    appState

    The instance that called this delegate method.

    didUpdateTimerStatus

    The timer setting tuple that was affected.

    from

    The original state before the change.

  • Called when the timer mode changes

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, didUpdateTimerDisplayMode: TimerSettingTuple, from: TimerDisplayMode)

    Parameters

    appState

    The instance that called this delegate method.

    didUpdateTimerDisplayMode

    The timer setting tuple that was affected.

    from

    The original state before the change.

  • Called when the timer current time changes

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, didUpdateTimerCurrentTime: TimerSettingTuple, from: Int)

    Parameters

    appState

    The instance that called this delegate method.

    didUpdateTimerCurrentTime

    The timer setting tuple that was affected.

    from

    The original time before the change.

  • Called when the timer warning time setting is changed

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, didUpdateTimerWarnTime: TimerSettingTuple, from: Int)

    Parameters

    appState

    The instance that called this delegate method.

    didUpdateTimerWarnTime

    The timer setting tuple that was affected.

    from

    The original time before the change.

  • Called when the timer final time setting is changed

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, didUpdateTimerFinalTime: TimerSettingTuple, from: Int)

    Parameters

    appState

    The instance that called this delegate method.

    didUpdateTimerFinalTime

    The timer setting tuple that was affected.

    from

    The original time before the change.

  • Called when the timer starting time setting is changed

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, didUpdateTimerTimeSet: TimerSettingTuple, from: Int)

    Parameters

    appState

    The instance that called this delegate method.

    didUpdateTimerTimeSet

    The timer setting tuple that was affected.

    from

    The original time before the change.

  • Called when the timer sound ID setting is changed

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, didUpdateTimerSoundID: TimerSettingTuple, from: Int)

    Parameters

    appState

    The instance that called this delegate method.

    didUpdateTimerSoundID

    The timer setting tuple that was affected.

    from

    The original ID before the change.

  • Called when the timer song URL setting is changed

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, didUpdateTimerSongURL: TimerSettingTuple, from: String)

    Parameters

    appState

    The instance that called this delegate method.

    didUpdateTimerSongURL

    The timer setting tuple that was affected.

    from

    The original URL (as a String) before the change.

  • Called when the timer alert mode setting is changed

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, didUpdateTimerAlertMode: TimerSettingTuple, from: AlertMode)

    Parameters

    appState

    The instance that called this delegate method.

    didUpdateTimerAlertMode

    The timer setting tuple that was affected.

    from

    The original mode before the change.

  • Called when the timer sound mode setting is changed

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, didUpdateTimerSoundMode: TimerSettingTuple, from: SoundMode)

    Parameters

    appState

    The instance that called this delegate method.

    didUpdateTimerSoundMode

    The timer setting tuple that was affected.

    from

    The original mode before the change.

  • Called when the next timer ID setting is changed

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, didUpdateSucceedingTimerID: TimerSettingTuple, from: Int)

    Parameters

    appState

    The instance that called this delegate method.

    didUpdateSucceedingTimerID

    The timer setting tuple that was affected.

    from

    The original ID before the change.

  • Called when the audible ticks setting is changed

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, didUpdateAudibleTicks: TimerSettingTuple, from: Bool)

    Parameters

    appState

    The instance that called this delegate method.

    didUpdateAudibleTicks

    The timer setting tuple that was affected.

    from

    The original state before the change.

  • Called when the color theme setting is changed

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, didUpdateTimerColorTheme: TimerSettingTuple, from: Int)

    Parameters

    appState

    The instance that called this delegate method.

    didUpdateTimerColorTheme

    The timer setting tuple that was affected.

    from

    The original state before the change.

  • Called when a timer is added

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, didAddTimer: TimerSettingTuple)

    Parameters

    appState

    The instance that called this delegate method.

    didAddTimer

    The timer setting tuple that was affected.

  • Called when a timer is about to be removed

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, willRemoveTimer: TimerSettingTuple)

    Parameters

    appState

    The instance that called this delegate method.

    didAddTimer

    The timer setting tuple that will be removed.

  • Called when a timer was removed

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, didRemoveTimerAtIndex: Int)

    Parameters

    appState

    The instance that called this delegate method.

    didRemoveTimerAtIndex

    The 0-based index of the imer that was removed.

  • Called when a timer was selected

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, didSelectTimer: TimerSettingTuple!)

    Parameters

    appState

    The instance that called this delegate method.

    didSelectTimer

    The timer setting tuple that was affected. It is optional, as it is possible to select no timer.

  • Called when a timer was deselected

    Declaration

    Swift

    func appState(_ appState: LGV_Timer_State, didDeselectTimer: TimerSettingTuple)

    Parameters

    appState

    The instance that called this delegate method.

    didSelectTimer

    The timer setting tuple that was affected.

  • Declaration

    Swift

    subscript(index: Int) -> TimerSettingTuple { get }

    Parameters

    index

    The 0-based index of the requested element.

    Return Value

    The tuple at the given subscript.

  • Get the index of an element by its UUID

    Declaration

    Swift

    func indexOf(_ inUID: String) -> Int

    Parameters

    inUID

    The UUID of the element we’re looking for.

    Return Value

    The 0-based index of the given element.

  • Get the index of an element

    Declaration

    Swift

    func indexOf(_ inObject: TimerSettingTuple) -> Int

    Parameters

    inObject

    The element we’re looking for.

    Return Value

    The 0-based index of the given element.

  • See if our settings contain an object.

    Declaration

    Swift

    func contains(_ inObject: TimerSettingTuple) -> Bool

    Parameters

    inObject

    The element we’re looking for.

    Return Value

    true, if the settings array contains the given object.

  • See if our settings contain an object by its UUID.

    Declaration

    Swift

    func contains(_ inUID: String) -> Bool

    Parameters

    inUID

    The UUID of the element we’re looking for.

    Return Value

    true, if the settings array contains the given object.

  • Declaration

    Swift

    func makeIterator() -> AnyIterator<TimerSettingTuple>

    Return Value

    A new, initialized iterator of the settings.

  • Append a new object to the end of our array.

    Declaration

    Swift

    func append(_ inObject: TimerSettingTuple)

    Parameters

    inObject

    The object we’re appending.

  • Remove an object at the given 0-based index.

    Declaration

    Swift

    func remove(at index: Int)

    Parameters

    at

    The 0-based index of the object to be removed.

  • This is the callback that is made by the repeating timer.

    Declaration

    Swift

    @objc
    func timerCallback(_ inTimer: Timer)

    Parameters

    inTimer

    The Timer object that is calling this.