Good evening lovely community,
this is my first post, please have mercy, if I do something wrong.
I know there are some similar questions here, but I doesn\'t under
If you look at the declaration for Int's initializer that takes a String, you can see by the ? after init that it returns an optional:
convenience init?(_ description: String)
This means you have to unwrap it before you can do most things with it (== is an exception, since the Optional type has an overload for that operator).
There are four main ways to unwrap your optionals:
if let goalOne = Int(someString) {
// do something with goalOne
}
guard let goalOne = Int(someString) else {
// either return or throw an error
}
// do something with goalOne
map and/or flatMaplet someValue = Int(someString).map { goalOne in
// do something with goalOne and return a value
}
let goalOne = Int(someString) ?? 0 // Or whatever the default value should be
If you unwrap all your optionals, you'll be able to compare them as you expect.