Provides support for iCalendar RRULE expressions including an extension to EventKit allowing you to create an EKRecurrenceRule from an RRULE expression and to enumerate the dates of an EKEvent.
For complete details about iCalendar RRULE expressions, see the Format Definition and examples at iCalendar.org.
Note that you do not need to make any use of RRULE expressions to use this framework. If you just want to enumerate the dates of an EKEvent, you can use this framework to do so without any use or knowledge of RRULE syntax.
RWMRecurrenceRule can be used with iOS 9.0 and later, macOS 10.12 and later, and watchOS 2.0 and later.
This first example shows how you can enumerate the dates of some events in your calendar. This
listDates
function would need to be called after gaining permission to access the event store.
import EventKit
import RWMRecurrenceRule
func listDates(from store: EKEventStore) {
let start = Date()
let end = Calendar.current.date(byAdding: .month, value: 3, to: start)!
// Get events from the next 3 months
let pred = store.predicateForEvents(withStart: start, end: end, calendars: nil)
// Iterate through the events
store.enumerateEvents(matching: pred) { (event, stop) in
print("Event: \(event.title)")
var count = 0
// Iterate through the first 20 occurrences of the event
event.enumerateDates { (date, stop) in
print(date)
count += 1
if count > 20 {
stop = true
}
}
}
}
This example shows how to create an RWMRecurrenceRule
from an RRULE and then list its dates.
import EventKit
import RWMRecurrenceRule
// Every 4 days, 10 occurrences
let rule = "RRULE:FREQ=DAILY;INTERVAL=4;COUNT=10"
let parser = RWMRuleParser()
if let rules = parser.parse(rule: rule) {
let scheduler = RWMRuleScheduler()
let start = Date()
scheduler.enumerateDates(with: rules, startingFrom: start, using: { (date, stop) in
if let date = date {
print(date)
}
})
}
Feel free to experiment from Xcode using the project's playground.
Note: RWMRecurrenceRule requires Swift 4.1 and Xcode 9.3.
CocoaPods is a dependency manager for Cocoa projects. To install RWMRecurrenceRule with CocoaPods:
-
Make sure CocoaPods is installed. (RWMRecurrenceRule requires version 1.0.0 or greater.)
# Using the default Ruby install will require you to use sudo when # installing and updating gems. [sudo] gem install cocoapods
-
Update your Podfile to include the following:
use_frameworks! target 'YourAppTargetName' do pod 'RWMRecurrenceRule', '~> 0.0.2' end
-
Run
pod install --repo-update
.
The Swift Package Manager is a tool for managing the distribution of Swift code.
- Add the following to your
Package.swift
file:
dependencies: [
.package(url: "https://github.com/rmaddy/RWMRecurrenceRule.git", from: "0.0.2")
]
- Build your project:
$ swift build
To install RWNRecurrenceRule as an Xcode sub-project:
-
Drag the RWMRecurrenceRule.xcodeproj file into your own project. (Submodule, clone, or download the project first.)
-
In your target’s General tab, click the + button under Linked Frameworks and Libraries.
-
Select the appropriate RWMRecurrenceRule.framework for your platform.
-
Add.
Some additional steps are required to install the application on an actual device:
-
In the General tab, click the + button under Embedded Binaries.
-
Select the appropriate RWMRecurrenceRule.framework for your platform.
-
Add.
If you find any issues with RWMRecurrenceRule, please open an issue
RWMRecurrenceRule is available under the MIT license. See the LICENSE file for more information.