Writing one line code using the ternary operator:
let rawValue: String = ...
let subtype: String? = ...
let display = subtype != nil ? "\(rawValue) (\(subtype))" : rawValue
The compiler complains: String interpolation produces a debug description for an optional value; did you mean to make this explicit?
Add !
to force unwrapping subtype
in the string interpolation:
let display = subtype != nil ? "\(rawValue) (\(subtype!))" : rawValue
Now SwiftLint complains: Force Unwrapping Violation: Force unwrapping should be avoided. (force_unwrapping)
How to rewrite this one line code?