How to add an optional string extension?

后端 未结 9 519
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 23:44

You can create a String extension like so:

extension String {
   func someFunc -> Bool { ... }
}

but what if you want it to apply to opt

9条回答
  •  时光说笑
    2020-12-14 00:19

    In Swift 4.1 I was getting a Optional is ambiguous for type lookup in this context build error. To fix, you have to explicitly add the Swift namespace to the type:

    extension Swift.Optional where Wrapped == String {
        var isBlank: Bool {
            return self?.isBlank ?? true
        }
    }
    

提交回复
热议问题