How to tell if current running Apple Watch size/dimension is 38mm or 42mm?

Update Swift 4:

It includes new launch of Watch resolutions:

enum WatchResolution {
    case Watch38mm, Watch40mm,Watch42mm,Watch44mm, Unknown  
}

extension WKInterfaceDevice {
class func currentResolution() -> WatchResolution {
    let watch38mmRect = CGRect(x: 0, y: 0, width: 136, height: 170)
    let watch40mmRect = CGRect(x: 0, y: 0, width: 162, height: 197)
    let watch42mmRect = CGRect(x: 0, y: 0, width: 156, height: 195)
    let watch44mmRect = CGRect(x: 0, y: 0, width: 184, height: 224)

    let currentBounds = WKInterfaceDevice.current().screenBounds

    switch currentBounds {
    case watch38mmRect:
        return .Watch38mm
    case watch40mmRect:
        return .Watch40mm
    case watch42mmRect:
        return .Watch42mm
    case watch44mmRect:
        return .Watch44mm
    default:
        return .Unknown
    }
  } 
}

Usage

let resol = WKInterfaceDevice.currentResolution()
    switch resol {
    case .Watch38mm, .Watch42mm:
        // Do Something
    case .Watch40mm, .Watch44mm:
        // Do Something
    default:
        // Do Something
    }

Reference Link: Apple Developer Watch Interface Link

Hope that helps....

Thanks


Your method looks fine and nothing is wrong with it. Another solution is to use contentFrame property of the WKInterfaceController. If the width is 312(156) pixels then its 42mm else is 38mm.

enter image description here


This is what I am doing:

enum WatchModel {
    case w38, w40, w42, w44, unknown
}

extension WKInterfaceDevice {

    static var currentWatchModel: WatchModel {
        switch WKInterfaceDevice.current().screenBounds.size {
        case CGSize(width: 136, height: 170):
            return .w38
        case CGSize(width: 162, height: 197):
            return .w40
        case CGSize(width: 156, height: 195):
            return .w42
        case CGSize(width: 184, height: 224):
            return .w44
        default:
            return .unknown
    }
  }
}

Your code looks good, but has a few minor issues:

  • You don't have a case for an "unknown" screen size (possibly released in the future)
  • You're using CGRectMake but in Swift you should use a CGRect initializer
  • You're using CGRectEqualToRect but in Swift you can just use == or switch
  • You're explicitly returning WatchResolution enums, but you don't need to be explicit - Swift will figure it out from your method signature
  • You're declaring watch42mmRect but not using it for anything

I would rewrite it like this:

enum WatchResolution {
    case Watch38mm, Watch42mm, Unknown
}

extension WKInterfaceDevice {
    class func currentResolution() -> WatchResolution {
        let watch38mmRect = CGRect(x: 0, y: 0, width: 136, height: 170)
        let watch42mmRect = CGRect(x: 0, y: 0, width: 156, height: 195)

        let currentBounds = WKInterfaceDevice.currentDevice().screenBounds

        switch currentBounds {
        case watch38mmRect:
            return .Watch38mm
        case watch42mmRect:
            return .Watch42mm
        default:
            return .Unknown
        }
    }
}