diff --git a/Sources/DeviceModel.swift b/Sources/DeviceModel.swift index a4d25f2..38726cd 100644 --- a/Sources/DeviceModel.swift +++ b/Sources/DeviceModel.swift @@ -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 @@ -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 + } + } +} diff --git a/Tests/DeviceModelTests.swift b/Tests/DeviceModelTests.swift index 228ec74..0276e71 100644 --- a/Tests/DeviceModelTests.swift +++ b/Tests/DeviceModelTests.swift @@ -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) } + } } diff --git a/Tests/UIDeviceExtensionsTests.swift b/Tests/UIDeviceExtensionsTests.swift index e97bbf1..0c87d98 100644 --- a/Tests/UIDeviceExtensionsTests.swift +++ b/Tests/UIDeviceExtensionsTests.swift @@ -55,5 +55,4 @@ class UIDeviceExtensionsTests: XCTestCase { let deviceFamily = DeviceFamily(rawValue: "x86_64") XCTAssert(deviceFamily == .simulator, "DeviceExtensions - .isSimulator is failing") } - }