Skip to content

Instantly share code, notes, and snippets.

@tamaki-shingo
Created January 8, 2017 13:16
Show Gist options
  • Save tamaki-shingo/2adb155c41989f122c76613d07efb727 to your computer and use it in GitHub Desktop.
Save tamaki-shingo/2adb155c41989f122c76613d07efb727 to your computer and use it in GitHub Desktop.
String型のEnumだけに縛りたいならこうかな? #CodePiece
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