Creating sample data
As you saw in Chapter 14, Getting Started with MVC and Table Views, you can use an array as the data source for a table view. You will now create an extension containing a static method that will return an array containing three sample journal entries.
Click the JournalEntry
file in the Project navigator, and type in the following after all other code in the file:
// MARK: - Sample data
extension JournalEntry {
static func createSampleJournalEntryData() -> [JournalEntry] {
let photo1 = UIImage(systemName: "sun.max")
let photo2 = UIImage(systemName: "cloud")
let photo3 = UIImage(systemName: "cloud.sun")
guard let journalEntry1 = JournalEntry(rating: 5, title: "Good", body: "Today is a good day", photo: photo1) else {
fatalError("Unable to instantiate journalEntry1")
}
guard let journalEntry2 = JournalEntry(rating: 0, title: "Bad", body:...