I would like to subclass a class
that is implementing OptionSet
, so that I can add some additional options
only for this subclass
. Is this possible? I tried something like this:
extension AugmentedRealityViewSceneKit {
public class EngineConfiguration: OptionSet {
public static let enableSun = EngineConfiguration(rawValue: 1 << 0)
public static let enableFloor = EngineConfiguration(rawValue: 1 << 1)
public var rawValue: Int
required public init(rawValue: RawValue) {
self.rawValue = rawValue
}
}
}
extension AugmentedRealityViewARKit {
public class EngineConfiguration: AugmentedRealityViewSceneKit.EngineConfiguration {
public static let enableWorldTracking = EngineConfiguration(rawValue: 1 << 2)
public static let enableEnvironmentLightEstimation = EngineConfiguration(rawValue: 1 << 3)
public static let enableFloorLevelDetection = EngineConfiguration(rawValue: 1 << 4)
}
}
But this doesn't work when I try to check if option is in given set using .contains()
- it shows:
'AugmentedRealityViewARKit.EngineConfiguration' requires the types 'AugmentedRealityViewARKit.EngineConfiguration' and 'AugmentedRealityViewSceneKit.EngineConfiguration' be equivalent to use 'contains'
Example playground:
import UIKit
public class EngineConfigurationA: OptionSet {
public static let enableSun = EngineConfigurationA(rawValue: 1 << 0)
public static let enableFloor = EngineConfigurationA(rawValue: 1 << 1)
public var rawValue: Int
required public init(rawValue: RawValue) {
self.rawValue = rawValue
}
}
public class EngineConfigurationB: EngineConfigurationA {
public static let enableWorldTracking = EngineConfigurationB(rawValue: 1 << 2)
public static let enableEnvironmentLightEstimation = EngineConfigurationB(rawValue: 1 << 3)
public static let enableFloorLevelDetection = EngineConfigurationB(rawValue: 1 << 4)
}
let optionsB: EngineConfigurationB = [EngineConfigurationB.enableWorldTracking, EngineConfigurationA.enableSun]
let contains = optionsB.contains(EngineConfigurationB.enableWorldTracking)