Add PostStore method to update post's WFPost property

This commit is contained in:
Angelo Stavrow 2020-08-31 16:36:41 -04:00
parent 30b527daa4
commit 4ae66e1585
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE

View File

@ -1,4 +1,5 @@
import Foundation
import WriteFreely
struct PostStore {
var posts: [Post]
@ -23,7 +24,23 @@ struct PostStore {
if let localCopy = localCopy {
localCopy.wfPost.updatedDate = Date()
} else {
print("local copy not found")
print("Error: Local copy not found")
}
}
mutating func replace(post: Post, with fetchedPost: WFPost) {
// Find the local copy in the store.
let localCopy = posts.first(where: { $0.id == post.id })
// Replace the local copy's wfPost property with the fetched copy.
if let localCopy = localCopy {
localCopy.wfPost = fetchedPost
DispatchQueue.main.async {
localCopy.hasNewerRemoteCopy = false
localCopy.status = .published
}
} else {
print("Error: Local copy not found")
}
}