From 8dccdf1539e1e3f4675ff87f2bc6645b88785c4a Mon Sep 17 00:00:00 2001 From: Dennis Weissmann Date: Sun, 22 Feb 2015 13:40:30 +0100 Subject: [PATCH] Added Device A very basic Device type that is able to determine the current iDevice (idiom and generation). --- Device.swift | 101 ++++++++++++++++++++++++++++++++++++++++++++++ DeviceTests.swift | 22 ++++++++++ 2 files changed, 123 insertions(+) create mode 100644 Device.swift create mode 100644 DeviceTests.swift diff --git a/Device.swift b/Device.swift new file mode 100644 index 0000000..481a07d --- /dev/null +++ b/Device.swift @@ -0,0 +1,101 @@ +// +// UIDevice.extension.swift +// Basics +// +// Created by Dennis Weissmann on 11/16/14. +// Copyright (c) 2014 Hot Action Studios. All rights reserved. +// + +public enum Device { + case iPodTouch5 + case iPhone4 + case iPhone4S + case iPhone5 + case iPhone5C + case iPhone5S + case iPhone6 + case iPhone6Plus + case iPad2 + case iPad3 + case iPad4 + case iPadAir + case iPadAir2 + case iPadMini + case iPadMini2 + case iPadMini3 + case Simulator + case UnknownIdentifier(String) + + public init() { + var systemInfo = utsname() + uname(&systemInfo) + let machine = systemInfo.machine + let mirror = reflect(machine) + let identifier: String = { + var identifier = "" + for i in 0.. Bool { + if lhs.description == rhs.description { return true } + return false +} diff --git a/DeviceTests.swift b/DeviceTests.swift new file mode 100644 index 0000000..70ec6d6 --- /dev/null +++ b/DeviceTests.swift @@ -0,0 +1,22 @@ +// +// DeviceTests.swift +// Basics +// +// Created by Dennis Weissmann on 11/16/14. +// Copyright (c) 2015 Hot Action Studios. All rights reserved. +// + +import XCTest + +class DeviceTests: XCTestCase { + + func testDeviceSimulator() { + let device = Device() + XCTAssert(device == Device.Simulator, "Enum incorrect.") + } + + func testDeviceDescription() { + XCTAssert(Device().description == "Simulator", "Description incorrect.") + } + +}