Skip to content

Instantly share code, notes, and snippets.

@aimak
Created October 19, 2016 12:38
Show Gist options
  • Save aimak/ce34ebcd0750c48be211679780945087 to your computer and use it in GitHub Desktop.
Save aimak/ce34ebcd0750c48be211679780945087 to your computer and use it in GitHub Desktop.
optional init in Enum in Swift 2.3
enum Origin {
case Foo
case Bar
init?(value : String) {
return .Foo
}
}
@aimak
Copy link
Author

aimak commented Oct 19, 2016

return .Foo does not compile : 'nil' is the only return value permitted in an initializer

@ebluehands
Copy link

Why don't you use:

enum Origin: String

and use the free initializer with the rawValue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment