Skip to content

Commit

Permalink
Add property to determine if device is compatible with Apple Pencil (#…
Browse files Browse the repository at this point in the history
…179)

* Add property to determine is device is compatible with Apple Pencil

* Moved Apple Pencil code into separate extension. Added option set to describe which generation of the Apple Pencil is supported

* Updated spacing to satisfy swiftlint warnings

* Removed whitespace to satisfy Swiftlint
  • Loading branch information
SomeRandomiOSDev authored and denisenepraunig committed Apr 12, 2019
1 parent a6b5bb3 commit 494d13a
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 56 deletions.
45 changes: 44 additions & 1 deletion Source/Device.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,6 @@ public enum Device {
public var hasRoundedDisplayCorners: Bool {
return isOneOf(Device.allDevicesWithRoundedDisplayCorners)
}

#elseif os(tvOS)
/// All TVs
public static var allTVs: [Device] {
Expand Down Expand Up @@ -1191,3 +1190,47 @@ extension Device {
}
}
#endif

#if os(iOS)
// MARK: - Apple Pencil
extension Device {

/**
This option set describes the current Apple Pencils
- firstGeneration: 1st Generation Apple Pencil
- secondGeneration: 2nd Generation Apple Pencil
*/
public struct ApplePencilSupport: OptionSet {

public var rawValue: UInt

public init(rawValue: UInt) {
self.rawValue = rawValue
}

public static let firstGeneration = ApplePencilSupport(rawValue: 0x01)
public static let secondGeneration = ApplePencilSupport(rawValue: 0x02)
}

/// All Apple Pencil Capable Devices
public static var allApplePencilCapableDevices: [Device] {
return [.iPad6, .iPadAir3, .iPadMini5, .iPadPro9Inch, .iPadPro12Inch, .iPadPro12Inch2, .iPadPro10Inch, .iPadPro11Inch, .iPadPro12Inch3]
}

/// Returns supported version of the Apple Pencil
public var applePencilSupport: ApplePencilSupport {
switch self {
case .iPad6: return .firstGeneration
case .iPadAir3: return .firstGeneration
case .iPadMini5: return .firstGeneration
case .iPadPro9Inch: return .firstGeneration
case .iPadPro12Inch: return .firstGeneration
case .iPadPro12Inch2: return .firstGeneration
case .iPadPro10Inch: return .firstGeneration
case .iPadPro11Inch: return .secondGeneration
case .iPadPro12Inch3: return .secondGeneration
default: return []
}
}
}
#endif
Loading

0 comments on commit 494d13a

Please sign in to comment.