Created
June 18, 2018 20:21
-
-
Save novinfard/f5b8cb7ff2ea03b9dff239a3ed5a59cd to your computer and use it in GitHub Desktop.
[Enumeration with Associative members]
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
import Foundation | |
enum Product { | |
case Book(Int, String) | |
case Car(Int, Int, String) | |
} | |
let AhmadShahBook = Product.Book(10, "Ahmad Shah") | |
switch AhmadShahBook { | |
case .Book(let quantity, let name): | |
print("The book name is \(name) with \(quantity)") | |
case .Car(let quantity, let maxSpeed, let name): | |
print("The book name is \(name) with \(quantity) which can go up to \(maxSpeed)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment