Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning value of an item in an array gives Bound value in a conditional binding must be an Optional type

Tags:

swift

I am getting a compile error saying

Bound value in a conditional binding must be an Optional type

Below is a screenshot of the code

enter image description here

like image 748
Encore PTL Avatar asked Nov 01 '22 22:11

Encore PTL


1 Answers

You can convert the value of array[index] to an Optional doing something like this:

if let value = Int?(array[index]){
    result += value
}

That's if your array contains Ints. You could also use AnyObject?, but you'll get a warning from xcode.

like image 111
Connor Avatar answered Jan 04 '23 14:01

Connor