Created
November 9, 2017 10:12
-
-
Save MarioIannotta/8adc13f6d85e34836f370b1537c47b4c to your computer and use it in GitHub Desktop.
Use a.or(b) instead a ?? b
This file contains hidden or 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
import Foundation | |
extension Optional { | |
func or(_ wrappedItem: Wrapped) -> Wrapped { | |
return self ?? wrappedItem | |
} | |
func or(_ wrappedItem: Optional) -> Optional { | |
return self ?? wrappedItem | |
} | |
} | |
extension Optional where Wrapped == String { | |
var orEmpty: String { | |
return or("") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment