isNilOrEmpty

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

import Foundation

extension Optional where Wrapped == String {
    var isNilOrEmpty: Bool {
        self == nil || self == ""
    }
}

func handles(optionalString: String?) {
    if optionalString.isNilOrEmpty == false {
        // use `optionalString`
    }
}
Previous
Previous

orEmpty

Next
Next

if-else vs switch