-
Notifications
You must be signed in to change notification settings - Fork 451
Open
Description
DeviceKit/Source/Device.generated.swift
Lines 2108 to 2111 in 513b9d7
public static let firstGeneration = ApplePencilSupport(rawValue: 0x01) | |
public static let secondGeneration = ApplePencilSupport(rawValue: 0x02) | |
public static let firstGenerationUsbC = ApplePencilSupport(rawValue: 0x03) | |
public static let pro = ApplePencilSupport(rawValue: 0x04) |
If we consider the following code, it would not work well because of 0x03
can be subtracted by 0x01
and 0x02
in binary operation
extension ApplePencilSupport
func supportsHover() -> Bool {
// future proofing new apple pencils by using a black list here
self.subtracting([.firstGeneration, .secondGeneration]).isEmpty == false
}
}
let deviceA: ApplePencilSupport = [.pro] // supports hover
let deviceB: ApplePencilSupport = [.firstGenerationUsbC] // supports hover
let deviceC: ApplePencilSupport = [.firstGeneration, .secondGeneration] // no hover capability
let deviceD: ApplePencilSupport = [.secondGeneration, .firstGenerationUsbC] // supports hover
deviceA.supportsHover() // return true
deviceB.supportsHover() // return false but it should return true
deviceC.supportsHover() // return false
deviceD.supportsHover() // return false but it should return true
I believe the fix would look something like this
public static let firstGeneration = ApplePencilSupport(rawValue: 1 << 0) // 1
public static let secondGeneration = ApplePencilSupport(rawValue: 1 << 1) // 2
public static let firstGenerationUsbC = ApplePencilSupport(rawValue: 1 << 2) // 4
public static let pro = ApplePencilSupport(rawValue: 1 << 3) // 8
Metadata
Metadata
Assignees
Labels
No labels