尝试解决 "Unexpectedly found nil while unwrapping an Optional value Playground execution failed" 问题

Try to solve the "Unexpectedly found nil while unwrapping an Optional value Playground execution failed" problem

我是 xcode 的新手,我尝试了几乎所有可能的方法来解决“在展开可选值 Playground 执行失败时意外发现 nil”的问题。如果你能帮助我,我将不胜感激。谢谢

//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)

您的 aYear 变量为零。 playground 正在尝试访问此 nil 值,这导致 playground 失败。

aYear一个初始值,playground应该运行.

var aYear = 2021

您还应该从 isLeap 函数中删除 let year = 1900 行。使用 year 参数来确定年份是否为闰年。