Skip to content

Instantly share code, notes, and snippets.

@motokiee
Created November 14, 2015 08:29
Show Gist options
  • Save motokiee/a0abbadb73d3019d77b8 to your computer and use it in GitHub Desktop.
Save motokiee/a0abbadb73d3019d77b8 to your computer and use it in GitHub Desktop.
Associated Typeでパターンマッチ #CodePiece
enum Option {
case Regular(MoreOption)
case Irregular(MoreOption)
}
enum MoreOption {
case One, Two, Three
}
let os1 = Option.Regular(.One)
let os2 = Option.Regular(.Two)
let os3 = Option.Regular(.Three)
let oi1 = Option.Irregular(.One)
let oi2 = Option.Irregular(.Two)
let oi3 = Option.Irregular(.Three)
switch os1 {
case Option.Regular(.One): print("Option.Regular.One")
case Option.Regular(_): print("Option.Regular ")
case Option.Irregular(_): print("Option.Irregular")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment