diff --git a/Gif/RRuleSwiftExample.gif b/Gif/RRuleSwiftExample.gif new file mode 100644 index 0000000..5045b21 Binary files /dev/null and b/Gif/RRuleSwiftExample.gif differ diff --git a/LICENSE.md b/LICENSE.md new file mode 100755 index 0000000..5e85bbc --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Teambition + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..5d4c801 --- /dev/null +++ b/README.md @@ -0,0 +1,85 @@ +#RRuleSwift +Swift library for working with recurrence rules of calendar dates. + +![Example](Gif/RRuleSwiftExample.gif "RRuleSwiftExample") + +RRuleSwift is based on [rrule.js](https://github.com/jkbrzt/rrule). + +##How To Get Started +###Carthage +Specify "RRuleSwift" in your Cartfile: +```ogdl +github "teambition/RRuleSwift" +``` + +###Usage +##### Initialization +```swift +var recurrenceRule = RecurrenceRule(recurrenceWithFrequency: .Daily) +recurrenceRule.calendar = ... +recurrenceRule.frequency = ... +recurrenceRule.interval = ... +recurrenceRule.firstDayOfWeek = ... +recurrenceRule.startDate = ... +recurrenceRule.recurrenceEnd = ... +recurrenceRule.bysetpos = ... +recurrenceRule.byyearday = ... +recurrenceRule.bymonth = ... +recurrenceRule.byweekno = ... +recurrenceRule.bymonthday = ... +recurrenceRule.byweekday = ... +recurrenceRule.byhour = ... +recurrenceRule.byminute = ... +recurrenceRule.bysecond = ... +``` + +##### Rule form string +```swift +let ruleString = "RRULE:FREQ=MONTHLY;DTSTART=20160404T021000Z;COUNT=5;INTERVAL=2;WKST=MO;BYDAY=MO,TU" +let rule = RecurrenceRule.ruleWithString(ruleString) +``` + +##### String form rule +```swift +let ruleString = rule.toRRuleString() +print(ruleString) +// RRULE:FREQ=MONTHLY;DTSTART=20160404T021000Z;COUNT=5;INTERVAL=2;WKST=MO;BYDAY=MO,TU +``` + +##### Occurrence generator +```swift +let ruleString = "RRULE:FREQ=YEARLY;COUNT=5;WKST=MO" +if let rule = RecurrenceRule.ruleWithString(ruleString) { + let allDates = rule.allOccurrences() + print(allDates) + /* + 2016-04-06 14:26:17 Wed, + 2017-04-06 14:26:17 Thu, + 2018-04-06 14:26:17 Fri, + 2019-04-06 14:26:17 Sat, + 2020-04-06 14:26:17 Mon + */ + + let date = dateFormatter.dateFromString("2017-01-01 00:00:00 Sun") + let otherDate = dateFormatter.dateFromString("2020-01-01 00:00:00 Wed") + let betweenDates = rule.occurrencesBetween(date: date!, andDate: otherDate!) + print(betweenDates) + /* + 2017-04-06 14:26:17 Thu, + 2018-04-06 14:26:17 Fri, + 2019-04-06 14:26:17 Sat + */ +} +``` + +## Minimum Requirement +iOS 8.0 + +## Release Notes +* [Release Notes](https://github.com/teambition/RRuleSwift/releases) + +## License +RRuleSwift is released under the MIT license. See [LICENSE](https://github.com/teambition/RRuleSwift/blob/master/LICENSE.md) for details. + +## More Info +Have a question? Please [open an issue](https://github.com/teambition/RRuleSwift/issues/new)! diff --git a/RRuleSwift/RecurrenceRule.swift b/RRuleSwift/RecurrenceRule.swift index cf44e03..e0681b6 100644 --- a/RRuleSwift/RecurrenceRule.swift +++ b/RRuleSwift/RecurrenceRule.swift @@ -14,7 +14,7 @@ public struct RecurrenceRule { public var calendar = NSCalendar.currentCalendar() /// The frequency of the recurrence rule. - public var frequency: RecurrenceFrequency! + public var frequency: RecurrenceFrequency /// Specifies how often the recurrence rule repeats over the unit of time indicated by its frequency. For example, a recurrence rule with a frequency type of RecurrenceFrequency.Weekly and an interval of 2 repeats every two weeks. /// diff --git a/RRuleSwiftExample/RRuleExampleViewController.swift b/RRuleSwiftExample/RRuleExampleViewController.swift index 93dd881..fc8e9a6 100644 --- a/RRuleSwiftExample/RRuleExampleViewController.swift +++ b/RRuleSwiftExample/RRuleExampleViewController.swift @@ -340,7 +340,7 @@ extension RRuleExampleViewController: UIPickerViewDataSource, UIPickerViewDelega func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { switch pickerView.tag { case 0: - rule.frequency = kFrequenciesDic[kFrequencies[row]] + rule.frequency = kFrequenciesDic[kFrequencies[row]]! case 1: rule.interval = row + 1 case 2: