Skip to content

Commit

Permalink
Merge pull request #38 from danramteke/master
Browse files Browse the repository at this point in the history
Add `hasNotch` property
  • Loading branch information
Nirma authored Jun 15, 2019
2 parents 29631f5 + 692b412 commit 68c146b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
16 changes: 15 additions & 1 deletion Sources/DeviceModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

public enum DeviceModel {
public enum DeviceModel: CaseIterable {

case iPhone4, iPhone4S
case iPhone5, iPhone5C, iPhone5S
Expand Down Expand Up @@ -201,3 +201,17 @@ extension DeviceModel {
}
}
}

// MARK: Detecting the Notch

extension DeviceModel {
public var hasNotch: Bool {
switch self {

case .iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR:
return true
default:
return false
}
}
}
11 changes: 10 additions & 1 deletion Tests/DeviceModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -311,5 +311,14 @@ class DeviceModelTests: XCTestCase {

XCTAssert(deviceModel == .unknown , "DeviceModel - .unknown is failing")
}


// MARK: Notch test
func testHasNotch() {
let notchModels: [DeviceModel] = [.iPhoneX, .iPhoneXS, .iPhoneXSMax, .iPhoneXR]

let noNotchModels: [DeviceModel] = DeviceModel.allCases.filter( { !notchModels.contains($0) })

notchModels.forEach { XCTAssertTrue($0.hasNotch) }
noNotchModels.forEach { XCTAssertFalse($0.hasNotch) }
}
}
1 change: 0 additions & 1 deletion Tests/UIDeviceExtensionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@ class UIDeviceExtensionsTests: XCTestCase {
let deviceFamily = DeviceFamily(rawValue: "x86_64")
XCTAssert(deviceFamily == .simulator, "DeviceExtensions - .isSimulator is failing")
}

}

0 comments on commit 68c146b

Please sign in to comment.