orEmpty

Here’s the code if you want to experiment with it:

import Foundation

extension Optional where Wrapped == String {
    var orEmpty: String {
        self ?? ""
    }
}

let optionalString = Bool.random() ? "Hello, world!" : nil

print(optionalString.orEmpty)
Previous
Previous

XCTest + try!

Next
Next

isNilOrEmpty