Created
October 6, 2016 10:09
-
-
Save shoheiyokoyama/dc8d064f5ac2d3f83578cc18600cb19b to your computer and use it in GitHub Desktop.
ネストされたenumを扱う ref: http://qiita.com/shoheiyokoyama/items/c32642606df0e37875dd
This file contains hidden or 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
| enum Japan { | |
| enum Tokyo: String { | |
| case shibuya, shinagawa, ebisu | |
| } | |
| enum Kanagawa: String { | |
| case yokohama, kawasaki, sagamihara | |
| } | |
| case tokyo(Tokyo) | |
| case kanagawa(Kanagawa) | |
| } | |
| func sayPlace(_ placeType: Japan) { | |
| let place: String = { | |
| switch placeType { | |
| case .tokyo(let place): return place.rawValue | |
| case .kanagawa(let place): return place.rawValue | |
| } | |
| }() | |
| print("\(place)!!!") | |
| } | |
| sayPlace(.tokyo(.ebisu)) // ebisu!!! | |
| sayPlace(.kanagawa(.yokohama)) // yokohama!!! | |
| sayPlace(.kanagawa(.sagamihara)) // sagamihara!!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment