Skip to content

Latest commit

 

History

History
111 lines (95 loc) · 2.27 KB

watchOS.md

File metadata and controls

111 lines (95 loc) · 2.27 KB

Device family

Simple code:

func watchOSDeviceFamily() {
    let family = Device.family()
    switch family {
    case .AppleWatch:
        print("Device belong to \(family) family")
    case .simulator:
        print("Device belong to \(family) family")
    case .unknown:
        print("unknown Device.")
    }
}

Device model

Simple code:

func watchOSDeviceModel() {
    let model = Device.model()
    print(model.identifier)
    switch model {
        /*** iPod ***/
    case .AppleWatch:
        print("Device is a \(model)")
    case .AppleWatchSeries1:
        print("Device is a \(model)")
    case .AppleWatchSeries2:
        print("Device is a \(model)")
    case .AppleWatchSeries3:
        print("Device is a \(model)")
    case .simulator(let model):
        print("Device is a \(model)")
    case .unknown:
        print("unknown Device.")
    }
}

Device screen size

Simple code:

func watchOSDeviceSize() {
    let size = Device.size()
    switch size {
    case .size38mm:
        print("Device size: \(size.description)")
    case .size42mm:
        print("Device size: \(size.description)")
    case .unknown:
        print("Device size unknown.")
    }
}

Helpers

Model

Simple code:

func watchOSModelHelper() {
    let model = Device.model()
    let allWatchs = Device.Model.allWatchs
    if allWatchs.contains(model) {
        print("Current device belong to Apple Watch")
    }
    let allSimulatorWatchs = Device.Model.allSimulatorWatchs
    if allSimulatorWatchs.contains(model) {
        print("Current device belong to Apple Watch Simulator")
    }
}

Size

You can use operator like >, <, >=, <=, ==, !=

Simple code:

func watchOSSizeHelper() {
    let size = Device.size()

    if size > .size38mm {
        print("Your device screen is larger than 38mm")
    }

    if size < .size38mm {
        print("Your device screen is smaller than 38mm")
    }

    if size >= .size38mm {
        print("Your device screen is equal or larger than 38mm")
    }

    if size <= .size38mm {
        print("Your device screen is equal or smaller than 38mm")
    }

    if size == .size38mm {
        print("It's a 38mm screen")
    }

    if size != .size42mm {
        print("It's not 42mm screen")
    }
}