<BlockSwitcher>

<Block name="Async/Await">

```swift
do {
    let posts = try await Amplify.DataStore.query(Post.self) 
    print("Posts retrieved successfully: \(posts)")
} catch let error as DataStoreError {
    print("Error retrieving posts \(error)")
} catch {
    print("Unexpected error \(error)")
}
```

</Block>

<Block name="Combine">

```swift
let sink = Amplify.Publisher.create {
    try await Amplify.DataStore.query(Post.self)
}.sink {
    if case let .failure(error) = $0 {
        print("Error retrieving posts \(error)")
    }
}
receiveValue: { posts in
    print("Posts retrieved successfully: \(posts)")
}
```

</Block>

</BlockSwitcher>
