Skip to content

Commit

Permalink
Swift 3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
hongxinhope committed Sep 22, 2016
1 parent 730db2a commit a4931bc
Show file tree
Hide file tree
Showing 25 changed files with 527 additions and 537 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ github "teambition/RRuleSwift"
###Usage
##### Initialization
```swift
var recurrenceRule = RecurrenceRule(frequency: .Daily)
var recurrenceRule = RecurrenceRule(frequency: .daily)
recurrenceRule.calendar = ...
recurrenceRule.frequency = ...
recurrenceRule.interval = ...
Expand All @@ -38,7 +38,7 @@ recurrenceRule.exdate = ...
##### Rule form string
```swift
let ruleString = "RRULE:FREQ=MONTHLY;DTSTART=20160404T021000Z;COUNT=5;INTERVAL=2;WKST=MO;BYDAY=MO,TU"
let rule = RecurrenceRule(recurrenceWithRRuleString: ruleString)
let rule = RecurrenceRule(rruleString: ruleString)
```

##### String form rule
Expand All @@ -63,7 +63,7 @@ if let inclusionDate = InclusionDate(rdateString: rdateString) {
}

let exdateString = "EXDATE:20181231T160000Z,20201231T160000Z"
if let exclusionDate = ExclusionDate(exdateString: exdateString, unitGranularity: .Year) {
if let exclusionDate = ExclusionDate(exdateString: exdateString, granularity: .year) {
print(exclusionDate.toExDateString())
// EXDATE:20181231T160000Z,20201231T160000Z

Expand All @@ -75,10 +75,10 @@ if let exclusionDate = ExclusionDate(exdateString: exdateString, unitGranularity
}
```

##### Occurrence generator
##### Occurrence iterator
```swift
let ruleString = "RRULE:FREQ=YEARLY;COUNT=11;WKST=MO"
if let rule = RecurrenceRule(recurrenceWithRRuleString: ruleString) {
if let rule = RecurrenceRule(rruleString: ruleString) {
var rule = rule
rule.rdate = inclusionDate // RDATE:20180706T160000Z,20210706T160000Z
rule.exdate = exclusionDate // EXDATE:20181231T160000Z,20201231T160000Z
Expand All @@ -97,9 +97,9 @@ if let rule = RecurrenceRule(recurrenceWithRRuleString: ruleString) {
2026-04-14 14:22:30 Tue
*/

let date = dateFormatter.dateFromString("2018-01-01 00:00:00 Sun")
let otherDate = dateFormatter.dateFromString("2024-01-01 00:00:00 Mon")
let betweenDates = rule.occurrencesBetween(date: date!, andDate: otherDate!)
let date = dateFormatter.date(from: "2018-01-01 00:00:00 Sun")!
let otherDate = dateFormatter.date(from: "2024-01-01 00:00:00 Mon")!
let betweenDates = rule.occurrences(between: date, and: otherDate)
print(betweenDates)
/*
2018-04-14 14:22:30 Sat
Expand Down
37 changes: 26 additions & 11 deletions RRuleSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
EB48D1621D641D45001EE872 /* EKWeekday+RRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB48D1511D641D45001EE872 /* EKWeekday+RRule.swift */; };
EB48D1631D641D45001EE872 /* ExclusionDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB48D1521D641D45001EE872 /* ExclusionDate.swift */; };
EB48D1641D641D45001EE872 /* ExclusionDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB48D1521D641D45001EE872 /* ExclusionDate.swift */; };
EB48D1651D641D45001EE872 /* Generators.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB48D1531D641D45001EE872 /* Generators.swift */; };
EB48D1651D641D45001EE872 /* Iterators.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB48D1531D641D45001EE872 /* Iterators.swift */; };
EB48D1671D641D45001EE872 /* InclusionDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB48D1541D641D45001EE872 /* InclusionDate.swift */; };
EB48D1681D641D45001EE872 /* InclusionDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB48D1541D641D45001EE872 /* InclusionDate.swift */; };
EB48D1691D641D45001EE872 /* JavaScriptBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = EB48D1551D641D45001EE872 /* JavaScriptBridge.swift */; };
Expand All @@ -34,7 +34,7 @@
EB48D1371D641AD6001EE872 /* RRuleSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RRuleSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
EB48D1511D641D45001EE872 /* EKWeekday+RRule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "EKWeekday+RRule.swift"; sourceTree = "<group>"; };
EB48D1521D641D45001EE872 /* ExclusionDate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExclusionDate.swift; sourceTree = "<group>"; };
EB48D1531D641D45001EE872 /* Generators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Generators.swift; sourceTree = "<group>"; };
EB48D1531D641D45001EE872 /* Iterators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Iterators.swift; sourceTree = "<group>"; };
EB48D1541D641D45001EE872 /* InclusionDate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InclusionDate.swift; sourceTree = "<group>"; };
EB48D1551D641D45001EE872 /* JavaScriptBridge.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JavaScriptBridge.swift; sourceTree = "<group>"; };
EB48D1571D641D45001EE872 /* nlp.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = nlp.js; sourceTree = "<group>"; };
Expand Down Expand Up @@ -91,7 +91,7 @@
EB48D15C1D641D45001EE872 /* RRule.swift */,
EB48D1521D641D45001EE872 /* ExclusionDate.swift */,
EB48D1541D641D45001EE872 /* InclusionDate.swift */,
EB48D1531D641D45001EE872 /* Generators.swift */,
EB48D1531D641D45001EE872 /* Iterators.swift */,
EB48D1551D641D45001EE872 /* JavaScriptBridge.swift */,
EB48D1511D641D45001EE872 /* EKWeekday+RRule.swift */,
EB48D1591D641D45001EE872 /* NSDate+Comparison.swift */,
Expand Down Expand Up @@ -184,14 +184,16 @@
D31B138E1CA8E02E00D0B863 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0730;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = Teambition;
TargetAttributes = {
D31B13961CA8E02E00D0B863 = {
CreatedOnToolsVersion = 7.3;
LastSwiftMigration = 0800;
};
EB48D1361D641AD6001EE872 = {
CreatedOnToolsVersion = 7.3;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -241,7 +243,7 @@
EB48D1631D641D45001EE872 /* ExclusionDate.swift in Sources */,
EB48D1711D641D45001EE872 /* RecurrenceFrequency.swift in Sources */,
EB48D1611D641D45001EE872 /* EKWeekday+RRule.swift in Sources */,
EB48D1651D641D45001EE872 /* Generators.swift in Sources */,
EB48D1651D641D45001EE872 /* Iterators.swift in Sources */,
EB48D1731D641D45001EE872 /* RecurrenceRule.swift in Sources */,
EB48D1691D641D45001EE872 /* JavaScriptBridge.swift in Sources */,
EB48D16F1D641D45001EE872 /* NSDate+Comparison.swift in Sources */,
Expand Down Expand Up @@ -280,8 +282,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -329,8 +333,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -350,6 +356,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -361,34 +368,38 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "Sources/Supporting Files/Info-iOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = Teambition.RRuleSwift;
PRODUCT_BUNDLE_IDENTIFIER = "Teambition.RRuleSwift-iOS";
PRODUCT_NAME = RRuleSwift;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
D31B13A11CA8E02E00D0B863 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "Sources/Supporting Files/Info-iOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = Teambition.RRuleSwift;
PRODUCT_BUNDLE_IDENTIFIER = "Teambition.RRuleSwift-iOS";
PRODUCT_NAME = RRuleSwift;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -397,21 +408,23 @@
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "Sources/Supporting Files/Info-watchOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.Teambition.RRuleSwift-watchOS";
PRODUCT_BUNDLE_IDENTIFIER = "Teambition.RRuleSwift-watchOS";
PRODUCT_NAME = RRuleSwift;
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME).h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 2.2;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
};
name = Debug;
};
Expand All @@ -420,20 +433,22 @@
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = "Sources/Supporting Files/Info-watchOS.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.Teambition.RRuleSwift-watchOS";
PRODUCT_BUNDLE_IDENTIFIER = "Teambition.RRuleSwift-watchOS";
PRODUCT_NAME = RRuleSwift;
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_OBJC_INTERFACE_HEADER_NAME = "$(SWIFT_MODULE_NAME).h";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 2.2;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
60 changes: 30 additions & 30 deletions RRuleSwiftExample-TodayExtension/TodayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,41 @@ import NotificationCenter
import RRuleSwift

class TodayViewController: UIViewController, NCWidgetProviding {
let dateFormatter: NSDateFormatter = {
let dateFormatter = NSDateFormatter()
dateFormatter.timeZone = NSTimeZone.defaultTimeZone()
dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
let dateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone.current
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss EEE"
return dateFormatter
}()

override func viewDidLoad() {
super.viewDidLoad()
var rule = RecurrenceRule(recurrenceWithRRuleString: "RRULE:FREQ=WEEKLY;DTSTART=20151119T014500Z;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR;UNTIL=20170101T014500Z")!
rule.exdate = ExclusionDate(exdateString: "EXDATE:20151120T014500Z,20151123T014500Z,20151126T014500Z,20151127T014500Z,20151130T014500Z,20151201T014500Z,20151202T014500Z,20151203T014500Z,20151207T014500Z,20151210T014500Z,20151211T014500Z,20151215T014500Z,20151216T014500Z,20151217T014500Z,20151221T014500Z,20151222T014500Z,20151223T014500Z,20151228T014500Z,20151229T014500Z", unitGranularity: .Day)
let date1 = dateFormatter.dateFromString("2016-06-06 00:00:00 Sun")!
let date2 = dateFormatter.dateFromString("2016-12-13 00:00:00 Sun")!
var rule = RecurrenceRule(rruleString: "RRULE:FREQ=WEEKLY;DTSTART=20151119T014500Z;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR;UNTIL=20170101T014500Z")!
rule.exdate = ExclusionDate(exdateString: "EXDATE:20151120T014500Z,20151123T014500Z,20151126T014500Z,20151127T014500Z,20151130T014500Z,20151201T014500Z,20151202T014500Z,20151203T014500Z,20151207T014500Z,20151210T014500Z,20151211T014500Z,20151215T014500Z,20151216T014500Z,20151217T014500Z,20151221T014500Z,20151222T014500Z,20151223T014500Z,20151228T014500Z,20151229T014500Z", granularity: .day)
let date1 = dateFormatter.date(from: "2016-06-06 00:00:00 Sun")!
let date2 = dateFormatter.date(from: "2016-12-13 00:00:00 Sun")!

let occurrences1 = rule.occurrencesBetween(date: date1, andDate: date2)
let occurrences2 = rule.occurrencesBetween(date: date1, andDate: date2)
let occurrences3 = rule.occurrencesBetween(date: date1, andDate: date2)
let occurrences4 = rule.occurrencesBetween(date: date1, andDate: date2)
let occurrences5 = rule.occurrencesBetween(date: date1, andDate: date2)
let occurrences6 = rule.occurrencesBetween(date: date1, andDate: date2)
let occurrences7 = rule.occurrencesBetween(date: date1, andDate: date2)
let occurrences8 = rule.occurrencesBetween(date: date1, andDate: date2)
let occurrences9 = rule.occurrencesBetween(date: date1, andDate: date2)
let occurrences10 = rule.occurrencesBetween(date: date1, andDate: date2)
let _ = rule.occurrencesBetween(date: date1, andDate: date2)
let _ = rule.occurrencesBetween(date: date1, andDate: date2)
let _ = rule.occurrencesBetween(date: date1, andDate: date2)
let _ = rule.occurrencesBetween(date: date1, andDate: date2)
let _ = rule.occurrencesBetween(date: date1, andDate: date2)
let _ = rule.occurrencesBetween(date: date1, andDate: date2)
let _ = rule.occurrencesBetween(date: date1, andDate: date2)
let _ = rule.occurrencesBetween(date: date1, andDate: date2)
let _ = rule.occurrencesBetween(date: date1, andDate: date2)
let _ = rule.occurrencesBetween(date: date1, andDate: date2)
let occurrences1 = rule.occurrences(between: date1, and: date2)
let occurrences2 = rule.occurrences(between: date1, and: date2)
let occurrences3 = rule.occurrences(between: date1, and: date2)
let occurrences4 = rule.occurrences(between: date1, and: date2)
let occurrences5 = rule.occurrences(between: date1, and: date2)
let occurrences6 = rule.occurrences(between: date1, and: date2)
let occurrences7 = rule.occurrences(between: date1, and: date2)
let occurrences8 = rule.occurrences(between: date1, and: date2)
let occurrences9 = rule.occurrences(between: date1, and: date2)
let occurrences10 = rule.occurrences(between: date1, and: date2)
let _ = rule.occurrences(between: date1, and: date2)
let _ = rule.occurrences(between: date1, and: date2)
let _ = rule.occurrences(between: date1, and: date2)
let _ = rule.occurrences(between: date1, and: date2)
let _ = rule.occurrences(between: date1, and: date2)
let _ = rule.occurrences(between: date1, and: date2)
let _ = rule.occurrences(between: date1, and: date2)
let _ = rule.occurrences(between: date1, and: date2)
let _ = rule.occurrences(between: date1, and: date2)
let _ = rule.occurrences(between: date1, and: date2)

print(occurrences1)
print(occurrences2)
Expand All @@ -64,13 +64,13 @@ class TodayViewController: UIViewController, NCWidgetProviding {

}

func widgetPerformUpdateWithCompletionHandler(completionHandler: ((NCUpdateResult) -> Void)) {
func widgetPerformUpdate(_ completionHandler: (@escaping (NCUpdateResult) -> Void)) {
// Perform any setup necessary in order to update the view.

// If an error is encountered, use NCUpdateResult.Failed
// If there's no update required, use NCUpdateResult.NoData
// If there's an update, use NCUpdateResult.NewData

completionHandler(NCUpdateResult.NewData)
completionHandler(NCUpdateResult.newData)
}
}
2 changes: 1 addition & 1 deletion RRuleSwiftExample-Watch Extension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<key>NSExtensionAttributes</key>
<dict>
<key>WKAppBundleIdentifier</key>
<string>Teambition.RRuleSwiftExample.watchkitapp</string>
<string>Teambition.RRuleSwiftExample.WatchKitApp</string>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.watchkit</string>
Expand Down
Loading

0 comments on commit a4931bc

Please sign in to comment.