Skip to content

Instantly share code, notes, and snippets.

@xxtesaxx
Created June 13, 2017 21:07
Show Gist options
  • Save xxtesaxx/23ddc2d061bc39dc89db31e160bc37ef to your computer and use it in GitHub Desktop.
Save xxtesaxx/23ddc2d061bc39dc89db31e160bc37ef to your computer and use it in GitHub Desktop.
struct MyStruct: Emptyable, CustomStringConvertible {
var name: String
var isEmpty: Bool { return name.isEmpty }
var description: String { return name }
init(name: String) {
self.name = name
}
}
var myOptional: MyStruct? = nil
myOptional.orWhenNilOrEmpty(MyStruct(name:"Hello World")) //"Hello World"
myOptional = MyStruct(name: "")
myOptional.orWhenNilOrEmpty(MyStruct(name:"Hello World")) //"Hello World"
myOptional = MyStruct(name: "Yeah")
myOptional.orWhenNilOrEmpty(MyStruct(name:"Hello World")) //"Yeah"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment