Created
March 21, 2018 18:27
-
-
Save hamsternik/e5e641f5f1e5b2027fd89e0c2d647a18 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| import CoreBluetooth | |
| enum BluetoothState: CustomStringConvertible { | |
| case off, on, unknown | |
| init(bluetoothState: CBManagerState) { | |
| switch bluetoothState { | |
| case .poweredOff: self = .off | |
| case .poweredOn: self = .on | |
| default: self = .unknown | |
| } | |
| } | |
| var description: String { | |
| switch self { | |
| case .off: return "Turned off" | |
| case .on: return "Turned on" | |
| case .unknown: return "Unknown" | |
| } | |
| } | |
| var color: UIColor { | |
| switch self { | |
| case .off: return .red | |
| case .on: return .green | |
| case .unknown: return .yellow | |
| } | |
| } | |
| } | |
| // MARK: - Case properties | |
| extension BluetoothState { | |
| var off: BluetoothState? { | |
| guard case .off = self else { | |
| return nil | |
| } | |
| return self | |
| } | |
| var on: BluetoothState? { | |
| guard case .on = self else { | |
| return nil | |
| } | |
| return self | |
| } | |
| var unknown: BluetoothState? { | |
| guard case .unknown = self else { | |
| return nil | |
| } | |
| return self | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment