Current code (this is the Time struct from the Comparable thread):
public struct Time: Comparable {
#if ELEMENTS
static func ==(_ lhs: Time, _ rhs: Time) -> Bool {
return lhs.hours == rhs.hours && lhs.minutes == rhs.minutes
}
static func <(_ lhs: Time, _ rhs: Time) -> Bool {
return lhs.hours < rhs.hours || (lhs.hours == rhs.hours && lhs.minutes < rhs.minutes)
}
static func <=(_ lhs: Time, _ rhs: Time) -> Bool {
return lhs < rhs || lhs == rhs
}
static func >=(_ lhs: Time, _ rhs: Time) -> Bool {
return !(lhs < rhs)
}
static func >(_ lhs: Time, _ rhs: Time) -> Bool {
return !(lhs <= rhs)
}
#endif
public var hours: Int = 127
public var minutes: Int = 127
public init() {
}
public func isValid() -> Bool {
return hours != 127 && minutes != 127
}
}
public struct DailySchedule {
static let length = 16
static let numPeriods = 8
fileprivate var _periods = [Time](repeating: Time(), count: DailySchedule.numPeriods)
var periods: [Time] {
get {
return _periods
}
set {
if newValue.count == DailySchedule.numPeriods {
_periods = newValue
} else {
_periods = [Time](repeating: Time(), count: DailySchedule.numPeriods)
}
}
}
// ...
}
I’m getting a “No matching overload” error message on DailySchedule
's fileprivate var _periods
line. It seems that the similar call in the setter seems to compile just fine. Similarly, moving the initialization of _periods
to init
also seems to resolve the issue.