MoonKit is a Swift package which uses math and trigonometry to compute several information about the Moon.
MoonKit only needs a location and the relative time zone to compute every Moon information.
Everything is computed locally, no internet connection is needed.
// Creating a CLLocation object with the coordinates you are interested in
let naplesLocation: CLLocation = .init(latitude: 40.84014, longitude: 14.25226)
// Timezone for the location of interest. It's highly recommended to initialize it via identifier
let timeZoneNaples: Timezone = .init(identifier: "Europe/Rome") ?? .current
// Creating the Moon instance which will store all the information you need about Moon events and her position
var myMoon: Moon = .init(location: naplesLocation, timeZone: timeZoneNaples)
// Creating a Date instance
let myDate: Date = Date() // Your current date
// Setting inside myMoon object the date of interest
myMoon.setDate(myDate)
// All the following informations are related to the given location for the date that has just been set
// Azimuth of the Moon
myMoon.azimuth
// Altitude of the Moon
myMoon.altitude
// Moonrise Date
myMoon.moonRise
// Moonset Date
myMoon.moonSet
// Current Moon Phase
myMoon.currentMoonPhase
// Moon Astrological sign
myMoon.moonSign
// To know all the information you can retrieve go to the **Features** section.
To properly show the Moon Date Events use the following DateFormatter.
//Creting a DateFormatter
let dateFormatter = DateFormatter()
//Properly setting his attributes
dateFormatter.locale = .current
dateFormatter.timeZone = timeZoneNaples // It shall be the same as the one used to initilize myMoon
dateFormatter.timeStyle = .full
dateFormatter.dateStyle = .full
//Printing Moon Date Events with the correct Timezone
print("Moonrise: \(dateFormatter.string(from: myMoon.moonRise))")
Take a look to the other Package, this time about the Sun: SunKit.
link |
Stars: 55 |
Last commit: 14 weeks ago |
bug fix of 'The package does not work well with daylight saving time'
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics