|
| 1 | +# Extending `Calendar.RecurrenceRule.End` |
| 2 | + |
| 3 | +* Proposal: SF-NNNN |
| 4 | +* Author(s): Hristo Staykov <hstaykov@apple.com> |
| 5 | +* Review Manager: [Tina Liu](https://github.com/itingliu) |
| 6 | +* Status: **Active review** |
| 7 | +* Bugs: <rdar://134294130> |
| 8 | +* Implementation: [apple/swift-foundation#888](https://github.com/apple/swift-foundation/pull/888) |
| 9 | +* Previous Proposal: [SF-0009](0009-calendar-recurrence-rule.md) |
| 10 | + |
| 11 | +## Revision history |
| 12 | + |
| 13 | +* **v1** Initial version |
| 14 | + |
| 15 | +## Introduction |
| 16 | + |
| 17 | +In [SF-0009](0009-calendar-recurrence-rule.md) we introduced `Calendar.RecurrenceRule`. In this API, we represent the end of a recurrence rule with the struct `Calendar.RecurrenceRule.End`: |
| 18 | + |
| 19 | +```swift |
| 20 | +/// When a recurring event stops recurring |
| 21 | +public struct End: Sendable, Equatable { |
| 22 | + /// The event stops repeating after a given number of times |
| 23 | + /// - Parameter count: how many times to repeat the event, including |
| 24 | + /// the first occurrence. `count` must be greater |
| 25 | + /// than `0` |
| 26 | + public static func afterOccurrences(_ count: Int) -> Self |
| 27 | + /// The event stops repeating after a given date |
| 28 | + /// - Parameter date: the date on which the event may last occur. No |
| 29 | + /// further occurrences will be found after that |
| 30 | + public static func afterDate(_ date: Date) -> Self |
| 31 | + /// The event repeats indefinitely |
| 32 | + public static var never: Self |
| 33 | + |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +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. |
| 38 | + |
| 39 | +## Detailed design |
| 40 | + |
| 41 | +```swift |
| 42 | +public extension Calendar.RecurrenceRule.End { |
| 43 | + /// At most many times the event may occur |
| 44 | + /// This value is set when the struct was initialized with `.afterOccurrences()` |
| 45 | + @available(FoundationPreview 6.0.2, *) |
| 46 | + public var count: Int? { get } |
| 47 | + |
| 48 | + /// The latest date when the event may occur |
| 49 | + /// This value is set when the struct was initialized with `.afterDate()` |
| 50 | + @available(FoundationPreview 6.0.2, *) |
| 51 | + public var date: Date? { get } |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +where `FoundationPreview 6.0.2` is equivalent to `macOS 15.2, iOS 18.2, tvOS 18.2, watchOS 11.2`. |
| 56 | + |
| 57 | +## Impact on existing code |
| 58 | + |
| 59 | +None. |
0 commit comments