我是 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)
uj5u.com熱心網友回復:
你的aYear變數為零。Playground 試圖訪問這個 nil 值,這導致 Playground 失敗。
給aYear一個初始值,操場應該運行。
var aYear = 2021
您還應該let year = 1900從isLeap函式中洗掉該行。使用year引數確定年份是否為閏年。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/381580.html
標籤:代码
