How can i calculate the number of days in a year for any calendar, not just gregorian. I have tried this
NSUInteger *days = [[NSCalendar currentCalendar] range
Best solution found for this problem using SWIFT 5.3 and Xcode 12.
Put it into playgrounds, call the checkLeapYear function passing a year into it and play around.
func checkLeapYear(year: Int) {
if year % 4 == 0{
if year % 100 == 0 {
if year % 400 == 0{
print("\(year) is a Leap Year!")
} else {
print("\(year) is NOT a Leap Year!")
}
} else {
print("\(year) is a Leap Year!")
}
} else {
print("\(year) is NOT a Leap Year!")
}
}
The algorithm is quite tricky so I suggest you use the following logic when performing it on your own: