Make Post object conform to ObservableObject

This commit is contained in:
Angelo Stavrow 2020-07-28 12:45:11 -04:00
parent 81581a7c02
commit 4b4608709e
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 20 additions and 7 deletions

View File

@ -1,12 +1,25 @@
import Foundation
import WriteFreely
struct Post: Identifiable {
var id = UUID()
var title: String = "Title"
var body: String = "Write your post here..."
var createdDate: Date = Date()
var status: PostStatus = .draft
class Post: Identifiable, ObservableObject {
@Published var title: String
@Published var body: String
@Published var createdDate: Date
@Published var status: PostStatus
let id = UUID()
init(
title: String = "Title",
body: String = "Write your post here...",
createdDate: Date = Date(),
status: PostStatus = .draft
) {
self.title = title
self.body = body
self.createdDate = createdDate
self.status = status
}
}
let testPost = Post(

View File

@ -1,7 +1,7 @@
import SwiftUI
struct PostEditor: View {
@State var post: Post
@ObservedObject var post: Post
@State private var hasUnpublishedChanges: Bool = false
var body: some View {