Created
January 8, 2017 13:16
-
-
Save tamaki-shingo/2adb155c41989f122c76613d07efb727 to your computer and use it in GitHub Desktop.
String型のEnumだけに縛りたいならこうかな? #CodePiece
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
protocol UUIDRepresentable: RawRepresentable { | |
} | |
extension UUIDRepresentable where Self.RawValue == String { | |
func uuid() -> String { | |
return self.rawValue | |
} | |
} | |
enum hogeInt : Int, UUIDRepresentable { | |
case one = 1 | |
case two = 2 | |
} | |
enum hogeString : String, UUIDRepresentable { | |
case foo = "foo" | |
case bar = "bar" | |
} | |
// hogeInt.one.uuid() //Error | |
hogeString.foo.uuid() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment