-
-
Save BoshiLee/442fe35c544c8ce636b1e6991b76e1c5 to your computer and use it in GitHub Desktop.
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
enum BookType: String { | |
case computer | |
case science | |
case language | |
static let cases: [BookType] = [.computer, .science, .language] | |
init?(_ ix: Int) { | |
guard ix < BookType.cases.count else { | |
return nil | |
} | |
self = BookType.cases[ix] | |
} | |
// init without saying rawvalue | |
init?(_ rawValue : String) { | |
self.init(rawValue: rawValue) | |
} | |
func nextCase() -> BookType { | |
var ix = BookType.cases.index(of: self) | |
ix = (ix! + 1) % BookType.cases.count | |
return BookType.cases[ix!] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment