Created
December 7, 2017 10:15
-
-
Save darthpelo/0a32b59f7353f61f8802f890927cf940 to your computer and use it in GitHub Desktop.
How to determinate Apple Watch model at runtime.
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 Foundation | |
import UIKit // Only to use CGFloat 😬 | |
import WatchKit | |
enum WatchModelType { | |
case large | |
case small | |
} | |
struct WatchModel { | |
static let largeWith: CGFloat = 156 | |
static let largeHeight: CGFloat = 195 | |
/// Returns the model of the Watch | |
/// | |
/// - Returns: the model of the Watch as `WatchModel` | |
static func model() -> WatchModelType { | |
// Watch 42mm bounds: (0.0, 0.0, 156.0, 195.0) | |
// Watch 38mm bounds: (0.0, 0.0, 136.0, 170.0) | |
let bounds = WKInterfaceDevice.current().screenBounds | |
switch (bounds.width, bounds.height) { | |
case (largeWith, largeHeight): | |
return .large | |
default: | |
return .small | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment