Skip to content

Instantly share code, notes, and snippets.

@mlvea
Last active August 29, 2015 14:27
Show Gist options
  • Save mlvea/143e19f4509772ae418f to your computer and use it in GitHub Desktop.
Save mlvea/143e19f4509772ae418f to your computer and use it in GitHub Desktop.
Swift Valid and Invalid enums with reasons
//Define a class Cat
class Cat {
}
enum EnumWithRaw : Cat{
/*
INVALID
[Error]: Raw Type Cat is not convertible from any literal
[Reason]: Raw value of enum have to be of type strings, characters, or any of the integer or floating-point number types.
Which is convertible from literal.
I explained what is literal in another issue here. http://stackoverflow.com/a/28935922/1239426
*/
}
// OK. Then what is valid. This one?
enum EnumWithRawNoCase : Character{
/*
INVALID
[Error]: An Enum with no cases cannot declare a raw value.
[Reason]: Have to have at least one case.
*/
}
enum EnumWithValidRaw : Character{
case NewLine = "\n"
/*
VALID
Finally Valid.
*/
}
enum EnumWithoutAnyCase {
/*
VALID
Is is legal to just define an enum without raw value without members. No use though.
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment