mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Make Post object conform to ObservableObject
This commit is contained in:
parent
81581a7c02
commit
4b4608709e
@ -1,12 +1,25 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import WriteFreely
|
import WriteFreely
|
||||||
|
|
||||||
struct Post: Identifiable {
|
class Post: Identifiable, ObservableObject {
|
||||||
var id = UUID()
|
@Published var title: String
|
||||||
var title: String = "Title"
|
@Published var body: String
|
||||||
var body: String = "Write your post here..."
|
@Published var createdDate: Date
|
||||||
var createdDate: Date = Date()
|
@Published var status: PostStatus
|
||||||
var status: PostStatus = .draft
|
|
||||||
|
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(
|
let testPost = Post(
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct PostEditor: View {
|
struct PostEditor: View {
|
||||||
@State var post: Post
|
@ObservedObject var post: Post
|
||||||
@State private var hasUnpublishedChanges: Bool = false
|
@State private var hasUnpublishedChanges: Bool = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
Loading…
Reference in New Issue
Block a user