-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJournalEntryLast.swift
53 lines (49 loc) · 1.74 KB
/
JournalEntryLast.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// JournalEntry.swift
// JRNL
//
// Created by iOS17Programming on 05/10/2023.
//
import UIKit
class JournalEntry {
// MARK: - Properties
let date: Date
let rating: Int
let entryTitle: String
let entryBody: String
let photo: UIImage?
let latitude: Double?
let longitude: Double?
// MARK: - Initialization
init?(rating: Int, title: String, body: String, photo: UIImage? = nil, latitude: Double? = nil, longitude: Double? = nil) {
if title.isEmpty || body.isEmpty || rating < 0 || rating > 5 {
return nil
}
self.date = Date()
self.rating = rating
self.entryTitle = title
self.entryBody = body
self.photo = photo
self.latitude = latitude
self.longitude = longitude
}
}
// 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: "Today is a bad day", photo: photo2) else {
fatalError("Unable to instantiate journalEntry2")
}
guard let journalEntry3 = JournalEntry(rating: 3, title: "Ok", body: "Today is an Ok day", photo: photo3) else {
fatalError("Unable to instantiate journalEntry3")
}
journalEntries += [journalEntry1, journalEntry2, journalEntry3]
}
}