Skip to content

Instantly share code, notes, and snippets.

@dmlebron
Last active November 6, 2018 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmlebron/db6c1d92d2e002ed11f2deea7c0f8414 to your computer and use it in GitHub Desktop.
Save dmlebron/db6c1d92d2e002ed11f2deea7c0f8414 to your computer and use it in GitHub Desktop.
struct MyObject {
var myProperty: String?
}
extension Optional where Wrapped == MyObject {
var unwrappedOrInit: MyObject {
switch self {
case .some(let unwrapped):
return unwrapped
case .none:
return MyObject()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment