You didn't provide a link to your earlier post, so I'm not sure what syntax you're fixing in this post, but if you mean that something like this doesn't compile:
data.result == result && data.variable?.starts(with: SomeString)
then that's because Swift's strong type system requires that the expressions on the left and right of &&
must be Bool
values. An optional value, which is the result of optional chaining (….variable?.…
, isn't a Bool
.
If that's what we're talking about, then you could do something like this:
data.result == result && data.variable?.starts(with: SomeString) != nil
The reason why data.variable!.starts(with: SomeString)
doesn't solve the problem is because it's going to abort at runtime if data.variable
is nil, and that's not the behavior you want here.