https://github.com/vsanthanam/viewscope
Better async contexts in SwiftUI
https://github.com/vsanthanam/viewscope
async await concurrency scope swiftui task
Last synced: 1 day ago
JSON representation
Better async contexts in SwiftUI
- Host: GitHub
- URL: https://github.com/vsanthanam/viewscope
- Owner: vsanthanam
- License: mit
- Created: 2025-12-18T18:19:14.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-12-24T05:07:04.000Z (5 months ago)
- Last Synced: 2026-04-24T10:40:30.510Z (about 1 month ago)
- Topics: async, await, concurrency, scope, swiftui, task
- Language: Swift
- Homepage: http://www.viewsco.pe/
- Size: 21.5 KB
- Stars: 15
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ViewScope
[](https://github.com/vsanthanam/ViewScope/blob/main/LICENSE)
[](https://github.com/vsanthanam/ViewScope/releases)
[](https://github.com/vsanthanam/ViewScope/actions)
[](https://swift.org)
[](https://www.viewsco.pe/docs/documentation/viewscope)
## Overview
ViewScope is a library that lets you create structured, SwiftUI-friendly async contexts for imperative asynchronous work, such as making a network request when a user taps on a button. It allows you to scope this work to a specific node in the SwiftUI view hiearchy and prevents you from needing to rely on unstructured concurrency to manage task cancellation.
For example:
```swift
import ViewScope
struct MyScreen: View {
@ViewScope myScope
var body: some View {
VStack {
Text("This screen can produce async side effects that need to be cancelled if it ever disappears, for example if the user interacts with a deeplink or dismisses a sheet presentation with a swipe")
Button("Make Network Request") {
myScope.task {
await makeNetworkRequest()
}
}
}
.whileVisible($myScope)
}
func makeNetworkRequest() async {
// Await things here
}
}
```
## Installation
ViewScope currently distributed exclusively through the [Swift Package Manager](https://www.swift.org/package-manager/).
To add ViewScope as a dependency to an existing Swift package, add the following line of code to the `dependencies` parameter of your `Package.swift` file:
```swift
dependencies: [
.package(url: "https://github.com/vsanthanam/ViewScope.git", from: "1.0.0")
]
```
To add ViewScope as a dependency to an Xcode Project:
- Choose `File` → `Add Packages...`
- Enter package URL `https://github.com/vsanthanam/ViewScope.git` and select your release and of choice.
Other distribution mechanisms like CocoaPods or Carthage may be added in the future.
## Usage & Documentation
ViewScope's documentation is built with [DocC](https://developer.apple.com/documentation/docc) and included in the repository as a DocC archive. The latest version is hosted on [GitHub Pages](https://pages.github.com) and is available [here](https://www.viewsco.pe/docs/documentation/viewscope)).
Additional installation instructions are available on the [Swift Package Index](https://swiftpackageindex.com/vsanthanam/ViewScope)
[](https://swiftpackageindex.com/vsanthanam/ViewScope)
[](https://swiftpackageindex.com/vsanthanam/ViewScope)
Explore [the documentation](https://www.viewsco.pe/docs/documentation/viewscope) for more details.
## License
**ViewScope** is available under the [MIT license](https://en.wikipedia.org/wiki/MIT_License). See the [LICENSE](https://github.com/vsanthanam/ViewScope/blob/main/LICENSE) file for more information.