print(device) // prints, for example, "iPhone 6 Plus"
if device == .iPhone6Plus { // Do something } else { // Do something else }
Get the Device Family
1 2 3 4 5 6 7 8
let device =Device() if device.isPod { // iPods (real or simulator) } elseif device.isPhone { // iPhone (real or simulator) } elseif device.isPad { // iPad (real or simulator) }
To check if running on Simulator
1 2 3 4 5
let device =Device() if device.isSimulator { // Running on one of the simulators(iPod/iPhone/iPad) // Skip doing something irrelevant for Simulator }
Get the Simulator Device
1 2 3 4 5 6
let device =Device() switch device { case .Simulator(.iPhone6s): break// You're running on the iPhone 6s simulator case .Simulator(.iPadAir2): break// You're running on the iPad Air 2 simulator default: break }
Make Sure the Device Is Contained in a Preconfigured Group
1 2 3 4 5 6
let groupOfAllowedDevices: [Device] = [.iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .Simulator(.iPhone6), .Simulator(.iPhone6Plus), .Simulator(.iPhone6s), .Simulator(.iPhone6sPlus)] let device =Device() if device.isOneOf(groupOfAllowedDevices) { // Do you action }
Get the Current Battery State
1 2 3
if device.batteryState == .Full|| device.batteryState >= .Charging(75) { print("Your battery is happy! 😊") }
Get the Current Battery Level
1 2 3 4 5
if device.batteryLevel >=50 { install_iOS() } else { showError() }