Skip to content

Commit

Permalink
Merge pull request #41 from schickling/issue-40
Browse files Browse the repository at this point in the history
Resolved allCases Issue
  • Loading branch information
codytwinton authored Apr 18, 2018
2 parents 6cd4337 + 63ac46e commit 7ddfe30
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,4 +18,4 @@

## 0.5.2

- **Update**: Update project settings to Swift 4
- **Update**: Update project settings to Swift 4
2 changes: 1 addition & 1 deletion Device.swift.podspec
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 2 additions & 6 deletions Device/UIDeviceExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,10 @@ internal protocol CaseIterable {
internal extension CaseIterable where Self: Hashable {
static var allCases: [Self] {
return [Self](AnySequence { () -> AnyIterator<Self> 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) }
}
})
}
Expand Down
19 changes: 15 additions & 4 deletions DeviceTests/DeviceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7ddfe30

Please sign in to comment.