Skip to content

Commit 12756ff

Browse files
committed
Add date to Book entity
1 parent 0d1c3dc commit 12756ff

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Bookworm/AddBookView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct AddBookView: View {
6464
newBook.rating = Int16(rating)
6565
newBook.genre = genre
6666
newBook.review = review
67+
newBook.date = Date.now
6768

6869
try? moc.save()
6970
dismiss()

Bookworm/Bookworm.xcdatamodeld/Bookworm.xcdatamodel/contents

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21513" systemVersion="22D68" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
33
<entity name="Book" representedClassName="Book" syncable="YES" codeGenerationType="class">
44
<attribute name="author" optional="YES" attributeType="String"/>
5+
<attribute name="date" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
56
<attribute name="genre" optional="YES" attributeType="String"/>
67
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
78
<attribute name="rating" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>

Bookworm/DetailView.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ struct DetailView: View {
4141

4242
RatingView(rating: .constant(Int(book.rating)))
4343
.font(.largeTitle)
44+
45+
Rectangle()
46+
.frame(height: 1)
47+
.foregroundColor(.secondary.opacity(0.5))
48+
.padding(.vertical)
49+
50+
HStack {
51+
Text("Added in:")
52+
Text(book.date ?? Date(), style: .date)
53+
}
4454
}
4555
.navigationTitle(book.title ?? "Unknown Book")
4656
.navigationBarTitleDisplayMode(.inline)

0 commit comments

Comments
 (0)