Basically, you did something that you do not need to do, and thus, you came across what was probably a compiler error (because the compiler did not stop you). Very nice!
Now the decision. You are obviously trying to deploy using Int!
. For safe deployment, use the for case
syntax:
let list:[Int?] = [1,2,3,4,5,6,7] for case let x? in list { print(x) // 1, 2, 3, 4, 5, 6, 7 }
Another way (same result):
let list:[Int?] = [1,2,3,4,5,6,7] list.flatMap{$0}.forEach{print($0)}
source share