diff --git a/CHANGELOG.md b/CHANGELOG.md index 842732d..eae0a57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.1.2 + +- **Fixed**: Resolved bug with allCases implementation + ## 1.1.1 - **Fixed**: Resolved bug with initialization via. device identifier @@ -14,4 +18,4 @@ ## 0.5.2 -- **Update**: Update project settings to Swift 4 \ No newline at end of file +- **Update**: Update project settings to Swift 4 diff --git a/Device.swift.podspec b/Device.swift.podspec index 970f1c2..455eae4 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.1" + s.version = "1.1.2" 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/UIDeviceExtension.swift b/Device/UIDeviceExtension.swift index 3e5efce..c8ba61f 100644 --- a/Device/UIDeviceExtension.swift +++ b/Device/UIDeviceExtension.swift @@ -229,14 +229,10 @@ internal protocol CaseIterable { internal extension CaseIterable where Self: Hashable { static var allCases: [Self] { return [Self](AnySequence { () -> AnyIterator in - var raw = 0 + var raw = -1 return AnyIterator { - let current = withUnsafeBytes(of: &raw) { $0.load(as: Self.self) } - guard current.hashValue == raw else { - return nil - } raw += 1 - return current + return withUnsafeBytes(of: &raw) { $0.load(as: Self.self) } } }) } diff --git a/DeviceTests/DeviceTests.swift b/DeviceTests/DeviceTests.swift index d7620b9..72f5a7f 100644 --- a/DeviceTests/DeviceTests.swift +++ b/DeviceTests/DeviceTests.swift @@ -99,34 +99,45 @@ class DeviceTests: XCTestCase { super.tearDown() } - func testExample() { - + func testCurrentDevice() { XCTAssertNotEqual(DeviceType.current, DeviceType.notAvailable) XCTAssertNotEqual(UIDevice.current.deviceType, DeviceType.notAvailable) + } + func testSimulatorTypes() { for type in simulatorTypes { let deviceType = DeviceType(identifier: type) XCTAssertEqual(deviceType, DeviceType.simulator) } + } + func testiPhoneTypes() { for type in iPhoneTypes { let deviceType = DeviceType(identifier: type) XCTAssertNotEqual(deviceType, DeviceType.notAvailable) } + } + func testiPodTypes() { for type in iPodTypes { let deviceType = DeviceType(identifier: type) XCTAssertNotEqual(deviceType, DeviceType.notAvailable) } - + } + + func testiPadTypes() { for type in iPadTypes { let deviceType = DeviceType(identifier: type) XCTAssertNotEqual(deviceType, DeviceType.notAvailable) } - + } + + func testEmptyDevice() { let emptyDevice = DeviceType(identifier: "") XCTAssertEqual(emptyDevice, DeviceType.notAvailable) + } + func testDeviceTypeAllCases() { XCTAssertEqual(DeviceType.allCases.count, 39) for type in DeviceType.allCases {