diff --git a/CHANGELOG.md b/CHANGELOG.md
index afeff70..842732d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog
+## 1.1.1
+
+- **Fixed**: Resolved bug with initialization via. device identifier
+
## 1.1
- **Add**: Support for iPad Pro 10.5
diff --git a/Device.swift.podspec b/Device.swift.podspec
index 69ce019..970f1c2 100755
--- a/Device.swift.podspec
+++ b/Device.swift.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Device.swift"
- s.version = "1.1"
+ s.version = "1.1.1"
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.summary = "Super-lightweight library to detect used device"
s.homepage = "https://github.com/schickling/Device.swift"
diff --git a/Device.xcodeproj/project.pbxproj b/Device.xcodeproj/project.pbxproj
index ef2a178..9d33ca6 100644
--- a/Device.xcodeproj/project.pbxproj
+++ b/Device.xcodeproj/project.pbxproj
@@ -146,7 +146,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
- LastUpgradeCheck = 0900;
+ LastUpgradeCheck = 0930;
TargetAttributes = {
8FBDE8941B5CFA1B00C78486 = {
CreatedOnToolsVersion = 7.0;
@@ -233,12 +233,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
@@ -290,12 +292,14 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
+ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
diff --git a/Device.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Device.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
new file mode 100644
index 0000000..18d9810
--- /dev/null
+++ b/Device.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
@@ -0,0 +1,8 @@
+
+
+
+
+ IDEDidComputeMac32BitWarning
+
+
+
diff --git a/Device.xcodeproj/xcshareddata/xcschemes/Device.xcscheme b/Device.xcodeproj/xcshareddata/xcschemes/Device.xcscheme
index d1729e3..4b18ffe 100644
--- a/Device.xcodeproj/xcshareddata/xcschemes/Device.xcscheme
+++ b/Device.xcodeproj/xcshareddata/xcschemes/Device.xcscheme
@@ -1,6 +1,6 @@
+ codeCoverageEnabled = "YES"
+ shouldUseLaunchSchemeArgsEnv = "YES">
@@ -57,7 +56,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
- language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
diff --git a/Device/Info.plist b/Device/Info.plist
index d3de8ee..c6f194e 100644
--- a/Device/Info.plist
+++ b/Device/Info.plist
@@ -15,7 +15,7 @@
CFBundlePackageType
FMWK
CFBundleShortVersionString
- 1.0
+ 1.1.1
CFBundleSignature
????
CFBundleVersion
diff --git a/Device/UIDeviceExtension.swift b/Device/UIDeviceExtension.swift
index 9bb1714..3e5efce 100644
--- a/Device/UIDeviceExtension.swift
+++ b/Device/UIDeviceExtension.swift
@@ -6,21 +6,15 @@
//
//
+// MARK: Imports
+
import Foundation
import UIKit
// MARK: -
-public extension UIDevice {
-
- /// Returns the `DeviceType` of the device in use
- public var deviceType: DeviceType {
- return DeviceType.current
- }
-}
-
/// Enum representing the different types of iOS devices available
-public enum DeviceType: String, EnumProtocol {
+public enum DeviceType: String, CaseIterable {
case iPhone2G
case iPhone3G
@@ -75,9 +69,9 @@ public enum DeviceType: String, EnumProtocol {
case simulator
case notAvailable
- // MARK: - Constants
+ // MARK: Constants
- /// Returns the current device type
+ /// The current device type
public static var current: DeviceType {
var systemInfo = utsname()
@@ -98,7 +92,7 @@ public enum DeviceType: String, EnumProtocol {
// MARK: Variables
- /// Returns the display name of the device type
+ /// The display name of the device type
public var displayName: String {
switch self {
@@ -144,6 +138,7 @@ public enum DeviceType: String, EnumProtocol {
}
}
+ /// The identifiers associated with each device type
internal var identifiers: [String] {
switch self {
@@ -192,15 +187,14 @@ public enum DeviceType: String, EnumProtocol {
}
}
- // MARK: - Inits
+ // MARK: Inits
- /** Creates a device type
- - parameter identifier: The identifier of the device
- - returns: The device type based on the provided identifier
- */
+ /// Creates a device type
+ ///
+ /// - Parameter identifier: The identifier of the device
internal init(identifier: String) {
- for device in DeviceType.all {
+ for device in DeviceType.allCases {
for deviceId in device.identifiers {
guard identifier == deviceId else { continue }
self = device
@@ -212,32 +206,40 @@ public enum DeviceType: String, EnumProtocol {
}
}
+// MARK: -
-// MARK: - EnumProtocol
+public extension UIDevice {
-internal protocol EnumProtocol: Hashable {
- /// -returns: All Enum Values
- static var all: [Self] { get }
+ /// The `DeviceType` of the device in use
+ public var deviceType: DeviceType {
+ return DeviceType.current
+ }
}
+#if swift(>=4.2)
+#else
+
// MARK: -
-// MARK: - Extensions
+internal protocol CaseIterable {
+ associatedtype AllCases: Collection where AllCases.Element == Self
+ static var allCases: AllCases { get }
+}
-internal extension EnumProtocol {
-
- static var all: [Self] {
- typealias Type = Self
- let cases = AnySequence { () -> AnyIterator in
+internal extension CaseIterable where Self: Hashable {
+ static var allCases: [Self] {
+ return [Self](AnySequence { () -> AnyIterator in
var raw = 0
return AnyIterator {
- let current: Self = withUnsafePointer(to: &raw) { $0.withMemoryRebound(to: Type.self, capacity: 1) { $0.pointee } }
- guard current.hashValue == raw else { return nil }
+ let current = withUnsafeBytes(of: &raw) { $0.load(as: Self.self) }
+ guard current.hashValue == raw else {
+ return nil
+ }
raw += 1
return current
}
- }
-
- return Array(cases)
+ })
}
}
+
+#endif
diff --git a/DeviceTests/DeviceTests.swift b/DeviceTests/DeviceTests.swift
index 1fc0db6..d7620b9 100644
--- a/DeviceTests/DeviceTests.swift
+++ b/DeviceTests/DeviceTests.swift
@@ -11,6 +11,7 @@ import XCTest
fileprivate extension DeviceType {
+ /// The test identifers to test against
var testIdentifiers: [String] {
switch self {
@@ -125,10 +126,11 @@ class DeviceTests: XCTestCase {
let emptyDevice = DeviceType(identifier: "")
XCTAssertEqual(emptyDevice, DeviceType.notAvailable)
+
+ XCTAssertEqual(DeviceType.allCases.count, 39)
- for type in DeviceType.all {
+ for type in DeviceType.allCases {
XCTAssertFalse(type.displayName.isEmpty)
-
XCTAssert(type.identifiers == type.testIdentifiers)
}
}
diff --git a/README.md b/README.md
index 2d87d45..884aada 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ var deviceType: DeviceType
Add the following to your `Cartfile` and follow [these instructions](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application)
-```
+```bash
github "schickling/Device.swift"
```
@@ -36,7 +36,6 @@ use_frameworks!
pod 'Device.swift'
```
-
## Usage
```swift
@@ -54,16 +53,12 @@ default: print("Check other available cases of DeviceType")
Also, check out our [Documentation][docs-url]
-
-
[carthage-image]: https://img.shields.io/badge/Carthage-compatible-4BC51D.svg
[docs-image]: https://img.shields.io/cocoapods/metrics/doc-percent/Device.swift.svg
-[lang-image]: https://img.shields.io/badge/swift-3.0-orange.svg
+[lang-image]: https://img.shields.io/badge/swift-4.1-orange.svg
[license-image]: https://img.shields.io/github/license/schickling/Device.swift.svg
[platform-image]: https://img.shields.io/cocoapods/p/Device.swift.svg
[pod-version-image]: https://img.shields.io/cocoapods/v/Device.swift.svg
-
-
[carthage-url]: https://github.com/Carthage/Carthage
[cocoapod-url]: http://cocoapods.org/pods/Device.swift
[docs-url]: http://cocoadocs.org/docsets/Device.swift