Created
June 13, 2017 21:07
-
-
Save xxtesaxx/23ddc2d061bc39dc89db31e160bc37ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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