`DeviceKit` is a value-type replacement of [`UIDevice`](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/).
## Changelog
Here you find an overview about all the latest features, bugfixes and breaking changes shipped with version 2.0 which was released on 10<sup>th</sup> April 2019.
### Breaking changes version 2.0
- The original `Device()` constructor has been made private in favour of using `Device.current` to match `UIDevice.current`.
- The enum values for the iPhone Xs, iPhone Xs Max and iPhone Xʀ have been renamed to be `.iPhoneXS`, `.iPhoneXSMax` and `.iPhoneXR` to match proper formatting.
-`.description` for the iPhone Xs, iPhone Xs Max and iPhone Xʀ have been changed to contain small caps formatting for the s and the ʀ part.
-`.description` for the iPad 5 and iPad 6 have been changed to the proper names; iPad (5<sup>th</sup> generation) and iPad (6<sup>th</sup> generation).
-`.name`, `.systemName`, `.systemVersion`, `.model`, `.localizedModel`, `.batteryState` and `.batteryLevel` will now all return nil when you try to get its value when the device you are getting it from isn't the current one. (eg. `Device.iPad6.name` while running on iPad 5)
### New features
- Updated to Swift 5!
- New `.allDevicesWithRoundedDisplayCorners` and `.hasRoundedDisplayCorners` values to check if a device has rounded display corners. (eg. iPhone Xs and iPad Pro (3<sup>rd</sup> generation))
- new `.allDevicesWithSensorHousing` and `.hasSensorHousing` values to check if a device has a screen cutout for the sensor housing. (eg. iPhone Xs)
### Bugfixes
-`.isPad` and `.isPhone` are now giving correct outputs again.
Here are some usage examples. All devices are also available as simulators:
```swift
.iPhone6=>.simulator(.iPhone6)
.iPhone6s=>.simulator(.iPhone6s)
```
You can try these examples in Playground.
**Note:**
> To try DeviceKit in the playground, open the `DeviceKit.xcworkspace` and build DeviceKit.framework for any simulator first by selecting "DeviceKit" as your current scheme.
### Get the Device You're Running On
```swift
letdevice=Device.current
print(device)// prints, for example, "iPhone 6 Plus"
ifdevice==.iPhone6Plus{
// Do something
}else{
// Do something else
}
```
### Get the Device Family
```swift
letdevice=Device.current
ifdevice.isPod{
// iPods (real or simulator)
}elseifdevice.isPhone{
// iPhone (real or simulator)
}elseifdevice.isPad{
// iPad (real or simulator)
}
```
### Check If Running on Simulator
```swift
letdevice=Device.current
ifdevice.isSimulator{
// Running on one of the simulators(iPod/iPhone/iPad)
// Skip doing something irrelevant for Simulator
}
```
### Get the Simulator Device
```swift
letdevice=Device.current
switchdevice{
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
> To get the current battery state we need to set `UIDevice.current.isBatteryMonitoringEnabled` to `true`. To avoid any issues with your code, we read the current setting and reset it to what it was before when we're done.
All model identifiers are taken from the following website: https://www.theiphonewiki.com/wiki/Models or extracted from the simulator app bundled with Xcode.
## Contributing
If you have the need for a specific feature that you want implemented or if you experienced a bug, please open an issue.
If you extended the functionality of DeviceKit yourself and want others to use it too, please submit a pull request.
## Contributors
The complete list of people who contributed to this project is available [here](https://github.com/devicekit/DeviceKit/graphs/contributors). DeviceKit wouldn't be what it is without you! Thank you very much! 🙏