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 a structure that has an array property containing three sample journal entries.
Click the JournalEntry
file in the Project navigator, and type in the following after the JournalEntry
class declaration:
// MARK: - Sample data
struct SampleJournalEntryData {
var journalEntries: [JournalEntry] = []
mutating func createSampleJournalEntryData() {
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...