Skip to content

Instantly share code, notes, and snippets.

@novinfard
Created June 18, 2018 20:21
Show Gist options
  • Save novinfard/f5b8cb7ff2ea03b9dff239a3ed5a59cd to your computer and use it in GitHub Desktop.
Save novinfard/f5b8cb7ff2ea03b9dff239a3ed5a59cd to your computer and use it in GitHub Desktop.
[Enumeration with Associative members]
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