【发布时间】:2018-03-07 19:48:46
【问题描述】:
我试图通过仅选择数组中的三个数字之一来让我的代码在 Swift 4 中打印“Hello World”,我得到了标题中列出的错误。
func newFunc() {
let employees = [1, 2, 3]?
if employees == [1] {
let printthis = "Hello World!"
print(printthis)
} else {
print("Nothing here")
}
}
newFunc()
【问题讨论】:
-
只需删除问号 ... 正如 Xcode 建议的 Fix-it
-
您的
if声明永远不会正确,因为[1,2,3]不等于[1]。