Update post in store async to avoid bad access error

This commit is contained in:
Angelo Stavrow 2020-08-27 17:40:05 -04:00
parent 00373e5a80
commit 201cc27162
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 17 additions and 2 deletions

View File

@ -14,4 +14,15 @@ struct PostStore {
mutating func purgeAllPosts() {
posts = []
}
}
mutating func update(_ post: Post) {
// Find the local copy in the store
let localCopy = posts.first(where: { $0.id == post.id })
// If there's a local copy, update the updatedDate property of its WFPost
if let localCopy = localCopy {
localCopy.wfPost.updatedDate = Date()
} else {
print("local copy not found")
}
}

View File

@ -48,7 +48,11 @@ struct PostEditorView: View {
}
})
.onDisappear(perform: {
post.wfPost.updatedDate = Date()
if post.status == .edited {
DispatchQueue.main.async {
model.store.update(post)
}
}
})
}