Swiftpack.co - Package - rmaddy/RWMRecurrenceRule

RWMRecurrenceRule

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.

Usage

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.

Installation

Note: RWMRecurrenceRule requires Swift 4.1 and Xcode 9.3.

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. To install RWMRecurrenceRule with CocoaPods:

  1. 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
    
  2. Update your Podfile to include the following:

    use_frameworks!
    
    target 'YourAppTargetName' do
        pod 'RWMRecurrenceRule', '~> 0.0.2'
    end
    
  3. Run pod install --repo-update.

Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code.

  1. Add the following to your Package.swift file:
dependencies: [
    .package(url: "https://github.com/rmaddy/RWMRecurrenceRule.git", from: "0.0.2")
]
  1. Build your project:
$ swift build

Manual

To install RWNRecurrenceRule as an Xcode sub-project:

  1. Drag the RWMRecurrenceRule.xcodeproj file into your own project. (Submodule, clone, or download the project first.)

    Installation Screen Shot

  2. In your target’s General tab, click the + button under Linked Frameworks and Libraries.

  3. Select the appropriate RWMRecurrenceRule.framework for your platform.

  4. Add.

Some additional steps are required to install the application on an actual device:

  1. In the General tab, click the + button under Embedded Binaries.

  2. Select the appropriate RWMRecurrenceRule.framework for your platform.

  3. Add.

Issues

If you find any issues with RWMRecurrenceRule, please open an issue

License

RWMRecurrenceRule is available under the MIT license. See the LICENSE file for more information.

Github

link
Stars: 1
Help us keep the lights on

Dependencies

Used By

Total: 0