young
(rtSwift)
1
I'm trying to compile this example in a Playground page:
import Foundation
public struct HeartRate: Hashable {
public let bpm: Double
public let interval: DateInterval
}
@dynamicMemberLookup public struct HeartRateContext: Equatable {
public enum Activity {
case sleep
case regular
case workout
}
public let age: Int
public let activity: Activity
private let heartRate: HeartRate
public init(age: Int, activity: Activity, heartRate: HeartRate) {
self.age = age
self.activity = activity
self.heartRate = heartRate
}
public subscript<Value> (dynamicMember keyPath: KeyPath<HeartRate, Value>) -> Value {
heartRate[keyPath: keyPath]
}
}
let heartRate = HeartRate(bpm: 100, interval: DateInterval())
let heartRateContext = HeartRateContext(age: 30, activity: .workout, heartRate: heartRate)
print (heartRateContext.bpm)
print (heartRateContext.activity)
get this compile error:
error: DynamicMemberLookup.xcplaygroundpage:8:24: 'DateInterval' is only available in iOS 10.0 or newer; clients of '__lldb_expr_16' may have a lower deployment target
public let interval: DateInterval
^
DynamicMemberLookup.xcplaygroundpage:6:15: note: add @available attribute to enclosing struct
public struct HeartRate: Hashable {
There is no problem with using DateInterval in another page. So this is a problem with this code.
What's wrong?