```swift
import SwiftUI
import Amplify
import Combine

/*
 Example showing how to observe the model and keep the state updated before performing a save. This uses the
 `@Published` property for views to observe and re-render changes to the model.
 */
class PostViewModel: ObservableObject {
    @Published var post: Post?
    var subscription: AnyCancellable?

    init() {
    }

    func observe(postId: String) {
        self.subscription = Amplify.Publisher.create(
            Amplify.DataStore.observeQuery(
                for: Post.self,
                where: Post.keys.id == postId
            )
        )
        .sink { completion in
            print("Completion event: \(completion)")
        } receiveValue: { snapshot in
            guard let post = snapshot.items.first else {
                return
            }
            DispatchQueue.main.async {
                self.post = post
            }
        }
    }

    func updateTitle(_ title: String) async {
        guard var post = post else {
            return
        }
        post.title = title
        do {
            let updatedPost = try await Amplify.DataStore.save(post)
            print("Updated post successfully: \(updatedPost)")
        } catch let error as DataStoreError {
            print("Failed to update post: \(error)")
        } catch {
            print("Unexpected error \(error)")
        }
    }
}
struct PostView: View {
    @StateObject var vm = PostViewModel()
    @State private var title = ""
    let postId: String

    init(postId: String) {
        self.postId = postId
    }

    var body: some View {
        VStack {
            Text("Post's current title: \(vm.post?.title ?? "")")
            TextField("Enter new title", text: $title)
            Button("Click to update the title to '\(title)'") {
                Task { await vm.updateTitle(title) }
            }
        }.onAppear(perform: {
            Task { await vm.observe(postId: postId) }
        })
    }
}
```
