|
1 | 1 | # WorldTimeAPI-ios |
| 2 | + |
| 3 | +[](https://github.com/Take111/WorldTimeAPI-ios/actions/workflows/main.yml) |
| 4 | + |
| 5 | +WorldTimeAPI-ios is a Swift package that provides a convenient way to interact with the WorldTime API. It allows iOS developers to easily fetch current time information for various timezones in their applications. |
| 6 | + |
| 7 | +> [!NOTE] |
| 8 | +> WorldTimeAPI-ios utilizes the WorldTime API. For detailed information and documentation about the WorldTime API, please refer to the following link: |
| 9 | +[WorldTime API Documentation](http://worldtimeapi.org/) |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +### Swift Package Manager |
| 14 | + |
| 15 | +You can add WorldTimeAPI-ios to your project using Swift Package Manager. In Xcode, go to File > Swift Packages > Add Package Dependency and enter the repository URL: |
| 16 | + |
| 17 | +``` |
| 18 | +https://github.com/Take111/WorldTimeAPI-ios.git |
| 19 | +``` |
| 20 | + |
| 21 | +Alternatively, you can add it to your `Package.swift` file: |
| 22 | + |
| 23 | +```swift |
| 24 | +dependencies: [ |
| 25 | + .package(url: "https://github.com/Take111/WorldTimeAPI-ios.git", from: "0.1.0") |
| 26 | +] |
| 27 | +``` |
| 28 | + |
| 29 | +## How to Use |
| 30 | + |
| 31 | +Here's a quick example of how to use WorldTimeAPI-ios in your project: |
| 32 | + |
| 33 | +```swift |
| 34 | +import WorldTimeAPIiOS |
| 35 | + |
| 36 | +let client = WorldTimeClient() |
| 37 | + |
| 38 | +// Fetch current time for a specific timezone |
| 39 | +do { |
| 40 | + let currentTime = try await client.fetchCurrentTime(with: .etc(.utc)) |
| 41 | + print("Current UTC time: \(currentTime.datetime)") |
| 42 | +} catch { |
| 43 | + print("Error fetching time: \(error)") |
| 44 | +} |
| 45 | + |
| 46 | +// Fetch current UTC time as a TimeInterval |
| 47 | +do { |
| 48 | + if let timeInterval = try await client.fetchUTCDateTimeInterval() { |
| 49 | + print("Current UTC time interval: \(timeInterval)") |
| 50 | + } |
| 51 | +} catch { |
| 52 | + print("Error fetching UTC time interval: \(error)") |
| 53 | +} |
| 54 | + |
| 55 | +// Fetch current UTC time as a Date |
| 56 | +do { |
| 57 | + if let date = try await client.fetchUTCDateTime() { |
| 58 | + print("Current UTC date: \(date)") |
| 59 | + } |
| 60 | +} catch { |
| 61 | + print("Error fetching UTC date: \(error)") |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +## Contribution |
| 66 | + |
| 67 | +Contributions to WorldTimeAPI-ios are welcome! Here's how you can contribute: |
| 68 | + |
| 69 | +1. Fork the repository |
| 70 | +2. Create your feature branch (`git checkout -b feature/AmazingFeature`) |
| 71 | +3. Commit your changes (`git commit -m 'Add some AmazingFeature'`) |
| 72 | +4. Push to the branch (`git push origin feature/AmazingFeature`) |
| 73 | +5. Open a Pull Request |
| 74 | + |
| 75 | +Please make sure to update tests as appropriate and adhere to the project's coding style. |
| 76 | + |
| 77 | +## License |
| 78 | + |
| 79 | +This project is licensed under the MIT License. However, please note that the API used in this project belongs to WorldTimeAPI. Be sure to check the WorldTimeAPI's terms and conditions for usage of their API. |
0 commit comments