This error occurs when using compare
on a String
in Swift 5
, it accepts only StringProtocol
, but I want to use it on String
and can't find nowhere how to do it.
I've searched all over and can't understand what seems to be the issue.
Problem that Optional<String>
(aka String?
) is not conform to StringProtocol
(and that makes sense). You should unwrap optional, there is several ways:
if let
/guard
(if let version = dbData?.version {
//compare
}
)dbData!.version
, which is highly not recommended, because it can involve crashing an app, if Optional was nil