Skip to content

Instantly share code, notes, and snippets.

@alexj70
Created April 22, 2017 19:54
Show Gist options
  • Save alexj70/2d6d02008e9144aed618cb1130d3eb41 to your computer and use it in GitHub Desktop.
Save alexj70/2d6d02008e9144aed618cb1130d3eb41 to your computer and use it in GitHub Desktop.
for case
enum Media {
case book(title: String, author: String, year: Int)
case movie(title: String, director: String, year: Int)
case website(urlString: String)
}
let mediaList: [Media] = [
.book(title: "Harry Potter and the Philosopher's Stone", author: "J.K. Rowling", year: 1997),
.movie(title: "Harry Potter and the Philosopher's Stone", director: "Chris Columbus", year: 2001),
.book(title: "Harry Potter and the Chamber of Secrets", author: "J.K. Rowling", year: 1999),
.movie(title: "Harry Potter and the Chamber of Secrets", director: "Chris Columbus", year: 2002),
.book(title: "Harry Potter and the Prisoner of Azkaban", author: "J.K. Rowling", year: 1999),
.movie(title: "Harry Potter and the Prisoner of Azkaban", director: "Alfonso Cuarón", year: 2004),
.movie(title: "J.K. Rowling: A Year in the Life", director: "James Runcie", year: 2007),
.website(urlString: "https://en.wikipedia.org/wiki/List_of_Harry_Potter-related_topics")
]
print("Movies only:")
for case let Media.movie(title, _, year) in mediaList {
print(" - \(title) (\(year))")
}
/* Output:
Movies only:
- Harry Potter and the Philosopher's Stone (2001)
- Harry Potter and the Chamber of Secrets (2002)
- Harry Potter and the Prisoner of Azkaban (2004)
- J.K. Rowling: A Year in the Life (2007)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment