SwiftCronParser is a Swift Package for parsing cron expressions.
- Swift 5.9+ (Xcode 15+)
- iOS 13+, macOS 10.15+
dependencies: [
.package(url: "https://github.com/0xWDG/SwiftCronParser.git", branch: "main"),
],
targets: [
.target(name: "MyTarget", dependencies: [
.product(name: "SwiftCronParser", package: "SwiftCronParser"),
]),
]
- In Xcode, open your project and navigate to File → Swift Packages → Add Package Dependency...
- Paste the repository URL (
https://github.com/0xWDG/SwiftCronParser
) and click Next. - Click Finish.
import SwiftUI
import SwiftCronParser
let cronParser = SwiftCronParser(input: "0 0 * * *")
let cronTime = cronParser.parse()
if let error = cronTime.error {
print("Error: \(error)")
} else {
print("Cron string: \(cronTime)") // 0 0 0,1,2,3,4,5,6 1,2,3,4,5,6,7,8,9,10,11,12 0,1,2,3,4,5,6
// Or using cronTime.minute, cronTime.hour, cronTime.dayOfMonth, cronTime.month, cronTime.dayOfWeek
}
This Blog post explains how I used this library in my app iWebTools.
🦋 @0xWDG 🐘 mastodon.social/@0xWDG 🐦 @0xWDG 🧵 @0xWDG 🌐 wesleydegroot.nl 🤖 Discord
Interested learning more about Swift? Check out my blog.