【发布时间】:2020-03-26 10:37:54
【问题描述】:
我正在尝试用 Swift 制作一个计算器,但我遇到了问题 我已将所有内容都放在一个数组中,并希望找到 X 和 /
的索引willBeCountArray.index(of: "x")
willBeCountArray.index(of: "/")
数组看起来像它应该的那样,它找到了索引,但它把它写成: 例如。
[1,x,5,+,4]
willBeCountArray.index(of: "x") 打印为 可选(1)`
--> 我想比较x和/index从左边开始。但它不会采用这种格式
我该怎么办?
【问题讨论】:
-
第 1 步:搜索 Stack Overflow! Printing optional variable
-
if let idx = willBeCountArray.index(of: "x") { print("found at index \(idx)") } else { print("not found") }