I saw this solution to someone, thanks, to this person, I donβt remember who.
infix operator ???: NilCoalescingPrecedence public func ???<T>(optional: T?, defaultValue: @autoclosure () -> String) -> String { switch optional { case let value?: return String(describing: value) case nil: return defaultValue() } }
For example:
let text = "\(yourInteger ??? "0")"
Mercedes
source share