Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility for Xcode 14 and XCFramework target #23

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ Carthage/Build
fastlane/report.xml
fastlane/screenshots

.DS_Store
/archives
/RRuleSwift.xcframework
19 changes: 19 additions & 0 deletions RRule/RRule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// RRule.h
// RRule
//
// Created by Nikhil Nigade on 28/11/22.
// Copyright © 2022 Teambition. All rights reserved.
//

#import <Foundation/Foundation.h>

//! Project version number for RRule.
FOUNDATION_EXPORT double RRuleVersionNumber;

//! Project version string for RRule.
FOUNDATION_EXPORT const unsigned char RRuleVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <RRule/PublicHeader.h>


19 changes: 19 additions & 0 deletions RRuleSwift-macOS/RRuleSwift_macOS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// RRuleSwift_macOS.h
// RRuleSwift-macOS
//
// Created by Nikhil Nigade on 26/08/21.
// Copyright © 2021 Teambition. All rights reserved.
//

#import <Foundation/Foundation.h>

//! Project version number for RRuleSwift_macOS.
FOUNDATION_EXPORT double RRuleSwift_macOSVersionNumber;

//! Project version string for RRuleSwift_macOS.
FOUNDATION_EXPORT const unsigned char RRuleSwift_macOSVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <RRuleSwift_macOS/PublicHeader.h>


263 changes: 249 additions & 14 deletions RRuleSwift.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
58 changes: 58 additions & 0 deletions RRuleSwift.xcodeproj/xcshareddata/xcschemes/RRule.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F0EB3A4D26D72D8E00FDA3AE"
BuildableName = "RRuleSwift.framework"
BlueprintName = "RRuleSwift-macOS"
ReferencedContainer = "container:RRuleSwift.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1400"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -29,8 +29,6 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -51,8 +49,6 @@
ReferencedContainer = "container:RRuleSwift.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "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 = "1020"
LastUpgradeVersion = "1400"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -29,8 +29,6 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -51,8 +49,6 @@
ReferencedContainer = "container:RRuleSwift.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
67 changes: 67 additions & 0 deletions RRuleSwift.xcodeproj/xcshareddata/xcschemes/XCFramework.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F05EA10A2934C8A900B30790"
BuildableName = "XCFramework"
BlueprintName = "XCFramework"
ReferencedContainer = "container:RRuleSwift.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F05EA10A2934C8A900B30790"
BuildableName = "XCFramework"
BlueprintName = "XCFramework"
ReferencedContainer = "container:RRuleSwift.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
2 changes: 2 additions & 0 deletions RRuleSwiftExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = "$(SRCROOT)/RRuleSwiftExample/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = Teambition.RRuleSwiftExample;
PRODUCT_NAME = RRuleSwiftExample;
Expand All @@ -585,6 +586,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = "$(SRCROOT)/RRuleSwiftExample/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = Teambition.RRuleSwiftExample;
PRODUCT_NAME = RRuleSwiftExample;
Expand Down
1 change: 1 addition & 0 deletions RRuleSwiftExample/RRuleExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class RRuleExampleViewController: UIViewController {
print(dateFormatter.string(from: occurrence))
}
print("\n")
print("text: \(String(describing: rule.toText()))")
}

@objc func resetButtonTapped(_ sender: UIBarButtonItem) {
Expand Down
9 changes: 6 additions & 3 deletions Sources/Iterators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@ import JavaScriptCore
public struct Iterator {
public static let endlessRecurrenceCount = 500
internal static let rruleContext: JSContext? = {
guard let rrulejs = JavaScriptBridge.rrulejs() else {
let scripts = JavaScriptBridge.rrulejs()
guard let rrulejs = scripts.lib,
let nlpJS = scripts.nlp else {
return nil
}
let context = JSContext()
context?.exceptionHandler = { context, exception in
print("[RRuleSwift] rrule.js error: \(String(describing: exception))")
}
let _ = context?.evaluateScript(rrulejs)
let _ = context?.evaluateScript(nlpJS)
return context
}()
}

public extension RecurrenceRule {
func allOccurrences(endless endlessRecurrenceCount: Int = Iterator.endlessRecurrenceCount) -> [Date] {
guard let _ = JavaScriptBridge.rrulejs() else {
guard let _ = JavaScriptBridge.rrulejs().lib else {
return []
}

Expand Down Expand Up @@ -57,7 +60,7 @@ public extension RecurrenceRule {
}

func occurrences(between date: Date, and otherDate: Date, endless endlessRecurrenceCount: Int = Iterator.endlessRecurrenceCount) -> [Date] {
guard let _ = JavaScriptBridge.rrulejs() else {
guard let _ = JavaScriptBridge.rrulejs().lib else {
return []
}

Expand Down
25 changes: 19 additions & 6 deletions Sources/JavaScriptBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,29 @@ import Foundation
import EventKit

internal struct JavaScriptBridge {
internal static func rrulejs() -> String? {
internal static func rrulejs() -> (lib: String?, nlp: String?) {

#if os(macOS)
let libPath = Bundle(identifier: "com.dezinezync.RRuleSwift-macOS")?.path(forResource: "rrule", ofType: "js") ?? Bundle.main.path(forResource: "rrule", ofType: "js")
let nlpPath = Bundle(identifier: "com.dezinezync.RRuleSwift-macOS")?.path(forResource: "nlp", ofType: "js") ?? Bundle.main.path(forResource: "nlp", ofType: "js")
#else
let libPath = Bundle(identifier: "Teambition.RRuleSwift-iOS")?.path(forResource: "rrule", ofType: "js") ?? Bundle.main.path(forResource: "rrule", ofType: "js")
guard let rrulelibPath = libPath else {
return nil
let nlpPath = Bundle(identifier: "Teambition.RRuleSwift-iOS")?.path(forResource: "nlp", ofType: "js") ?? Bundle.main.path(forResource: "nlp", ofType: "js")
#endif

guard let rrulelibPath = libPath,
let nlpPath else {
return (nil, nil)
}

do {
return try String(contentsOfFile: rrulelibPath)
} catch _ {
return nil
let lib = try String(contentsOfFile: rrulelibPath)
let nlp = try String(contentsOfFile: nlpPath)

return (lib, nlp)
}
catch _ {
return (nil, nil)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/RecurrenceFrequency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum RecurrenceFrequency {
case minutely
case secondly

internal func toString() -> String {
public func toString() -> String {
switch self {
case .secondly: return "SECONDLY"
case .minutely: return "MINUTELY"
Expand All @@ -27,7 +27,7 @@ public enum RecurrenceFrequency {
}
}

internal static func frequency(from string: String) -> RecurrenceFrequency? {
public static func frequency(from string: String) -> RecurrenceFrequency? {
switch string {
case "SECONDLY": return .secondly
case "MINUTELY": return .minutely
Expand Down
16 changes: 16 additions & 0 deletions Sources/RecurrenceRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,20 @@ public struct RecurrenceRule {
public func toRRuleString() -> String {
return RRule.stringFromRule(self)
}

#if os(iOS) || os(macOS)
public func toText() -> String? {
let paths = JavaScriptBridge.rrulejs()

guard let _ = paths.lib,
let _ = paths.nlp else {
return nil
}

let ruleJSONString = toJSONString(endless: Iterator.endlessRecurrenceCount)
let _ = Iterator.rruleContext?.evaluateScript("var rule = new RRule({ \(ruleJSONString) })")

return Iterator.rruleContext?.evaluateScript("rule.toText()").toString()
}
#endif
}