In SF-0009 we introduced Calendar.RecurrenceRule. In this API, we represent the end of a recurrence rule with the struct Calendar.RecurrenceRule.End:
/// When a recurring event stops recurring
public struct End: Sendable, Equatable {
/// The event stops repeating after a given number of times
/// - Parameter count: how many times to repeat the event, including
/// the first occurrence. `count` must be greater
/// than `0`
public static func afterOccurrences(_ count: Int) -> Self
/// The event stops repeating after a given date
/// - Parameter date: the date on which the event may last occur. No
/// further occurrences will be found after that
public static func afterDate(_ date: Date) -> Self
/// The event repeats indefinitely
public static var never: Self
}
This is de-facto an enum that was declared as struct to be future-proof. However, the original API only allowed construction of the recurrence rule end, and did not allow any introspection afterwards. This proposal adds a few properties to Calendar.RecurrenceRule.End to remedy this.
Detailed design
public extension Calendar.RecurrenceRule.End {
/// At most many times the event may occur
/// This value is set when the struct was initialized with `.afterOccurrences()`
@available(FoundationPreview 6.0.2, *)
public var count: Int? { get }
/// The latest date when the event may occur
/// This value is set when the struct was initialized with `.afterDate()`
@available(FoundationPreview 6.0.2, *)
public var date: Date? { get }
}
+1 makes complete sense. My only quibble would be that var count should probably be var occurrences, to match the afterOccurrences naming of the static constructor.
This is only used when printing, a localized description could fit in localizedDescription. In the context of RecurrenceRule, we would eventually want some sort of formatter to describe what the recurrence is. That is out of scope for this proposal.
There is one outstanding feedback, but I don't believe that is blocking, so I'll defer to @hsxc for his final decision. Meanwhile I'm going to conclude this review with accepted.