Im new to xcode and I tried almost anything I could in order to solve the "Unexpectedly found nil while unwrapping an Optional value Playground execution failed" problem. aprecciate a lot if you could help me . Thanks
//Don't change this
var aYear = Int(readLine()!)!
func isLeap(year: Int) {
let year = 1900
if year.isMultiple(of: 4) {
print("yes")
}
}
//Try out your function with some different years. Don't copy the line below (it's not part of the exercise you need to complete).
isLeap(year: aYear)
CodePudding user response:
Your aYear
variable is nil. The playground is trying to access this nil value, which causes the playground to fail.
Give aYear
an initial value, and the playground should run.
var aYear = 2021
You should also remove the let year = 1900
line from the isLeap
function. Use the year
argument to determine if the year is a leap year.