Skip to content

Instantly share code, notes, and snippets.

@darthpelo
Created December 7, 2017 10:15
Show Gist options
  • Save darthpelo/0a32b59f7353f61f8802f890927cf940 to your computer and use it in GitHub Desktop.
Save darthpelo/0a32b59f7353f61f8802f890927cf940 to your computer and use it in GitHub Desktop.
How to determinate Apple Watch model at runtime.
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