Network-time-synchronization in swift
- Network Time Protocol (NTP) support for accurate time synchronization.
- Easy to use API for fetching and using network time.
- Caching of server time for quick access.
- Compatible with iOS and macOS.
- iOS 17 and later
- macOS 14 and later
To add the NetTime package to your Swift project, add the following line to the dependencies
value of your Package.swift
.
.package(url: "https://github.com/sentryco/NetTime", branch: "main")
Then include "NetTime"
in the dependencies
value of any Target in which you want to use NetTime.
Here's an example of how to use NetTime:
import NetTime
Date.updateTime { // Call when app launches etc
print("βοΈ Current Date: \(Date().formatted())")
print("βοΈ Server time: \(Date.serverTime.formatted())")
}
Date.serverTime // Returns the cached server date
There are several libraries available for network time synchronization in Swift. Here are a few:
-
TrueTime.swift: An NTP client for Swift. This library allows you to get the "true" network time, and not rely on the device's system clock.
-
Kronos: Another NTP based time synchronization library developed by Lyft.
-
NetClock: A simple NTP client to get internet time in Swift.
-
SwiftNTP: A simple Network Time Protocol client written in Swift.
Tip
Remember to check the documentation and the community around these libraries to ensure they fit your needs and are actively maintained.
Contributions are welcome! Please read our contributing guidelines for details.
NetTime is released under the MIT License. See LICENSE for details.
- Do more exploration into side-effects
- Comb the competitors for ways to improve