Solar
A Swift helper for generating Sunrise and Sunset times.
Solar performs its calculations locally using an algorithm from the United States Naval Observatory, and thus does not require the use of a network.
Usage
Solar simply needs a date and a location specified as a latitude and longitude:
We can also omit providing a date if we just need the sunrise and sunset for the current date and time:
Note that all dates are UTC. Don't forget to format your date into the appropriate timezone if required.
Types of sunrise and sunset
There are several types of sunrise and sunset that Solar generates. They differ by how many degrees the sun lies below the horizon:
-
Official (~0°)
-
Civil (6° below horizon)
-
Nautical (12° below horizon)
-
Astronomical (18° below horizon)
For more information, see https://www.timeanddate.com/astronomy/different-types-twilight.html
Convenience methods
Solar also comes packaged with some convenience methods:
Installation
Solar is available through CocoaPods, Carthage, and Swift Package Manager.
CocoaPods
To include Solar in an application, add the following pod to your Podfile, then run pod install
:
To include Solar in another pod, add the following dependency to your podspec:
Carthage
Add the ceek/Solar
project to your Cartfile, then follow the rest of Carthage’s XCFramework installation instructions:
Swift Package Manager
To include Solar in an application in Xcode:
- Go to File ‣ Swift Packages ‣ Add Package Dependency.
- Enter
https://github.com/ceeK/Solar.git
as the package repository and click Next. - Set Rules to Version, Up to Next Major, and enter
3.0.0
as the minimum version requirement. Click Next.
To include Solar in another Swift package, add the following dependency to your Package.swift:
License
The MIT License (MIT)
Copyright (c) 2016-2021 Chris Howell