```swift
let post = Post(
title: "My first post",
status: .active
)
let user = User(
username: "Nadia"
)
let postEditor = PostEditor(
post: post,
user: user
)
do {
try await Amplify.DataStore.save(post)
try await Amplify.DataStore.save(user)
try await Amplify.DataStore.save(postEditor)
print("Saved post, user, and postEditor!")
} catch let error as DataStoreError {
print("Failed with error \(error)")
} catch {
print("Unexpected error \(error)")
}
```
```swift
let post = Post(
title: "My first post",
status: .active
)
let user = User(
username: "Nadia"
)
let postEditor = PostEditor(
post: post,
user: user
)
let sink = Amplify.Publisher.create{ try await Amplify.DataStore.save(post) }
.flatMap { _ in
Amplify.Publisher.create { try await Amplify.DataStore.save(user) }
}
.flatMap { _ in
Amplify.Publisher.create { try await Amplify.DataStore.save(postEditor) }
}
.sink {
if case let .failure(error) = $0 {
print("Error saving post, user and postEditor: \(error.localizedDescription)")
}
}
receiveValue: { _ in
print("Saved user, post and postEditor!")
}
```
This example illustrates the complexity of working with multiple dependent persistence operations. The callback model is flexible but imposes some challenges when dealing with such scenarios. Prefer to use the Combine model if your app supports iOS 13 or higher. If not, the recommendation is that you use multiple functions to simplify the code.