Last active
October 19, 2020 14:03
-
-
Save FahimF/100f3b0ee036ab60794a0a259dc2c118 to your computer and use it in GitHub Desktop.
Book model for use with UIListContentConfiguration examples
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 AuthorType { | |
case single, multiple | |
} | |
struct Book: Hashable { | |
var title = "" | |
var author = "" | |
var pages = 0 | |
var year = 0 | |
var genre = "" | |
var authType = AuthorType.single | |
static var sections: [String] { | |
return ["Fiction", "Non-Fiction"] | |
} | |
static var books: [String: [Book]] { | |
return [ | |
"Fiction": [ | |
Book(title: "Peace Talks", author:"Jim Butcher", pages: 340, year: 2020), | |
Book(title: "Battle Ground", author:"Jim Butcher", pages: 300, year: 2020), | |
Book(title: "Neuromancer", author:"William Gibson", pages: 271, year: 1984), | |
Book(title: "Snow Crash", author:"Neal Stephenson", pages: 480, year: 1992) | |
], | |
"Non-Fiction": [ | |
Book(title: "UIKit Apprentice", author:"Fahim Farook & Matthijs Hollemans", pages: 1128, year: 2020, authType: AuthorType.multiple), | |
Book(title: "Swift Apprentice", author:"The Ray Wenderlich Tutorial Team", pages: 500, year: 2020, authType: AuthorType.multiple) | |
] | |
] | |
} | |
static func booksFor(section: Int) -> [Book] { | |
let sec = Book.sections[section] | |
if let arr = Book.books[sec] { | |
return arr | |
} | |
return [] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment