https://github.com/noppefoxwolf/swiftdatauikit
https://github.com/noppefoxwolf/swiftdatauikit
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/noppefoxwolf/swiftdatauikit
- Owner: noppefoxwolf
- Created: 2024-03-11T14:56:37.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-11T18:47:12.000Z (over 2 years ago)
- Last Synced: 2025-06-03T11:32:43.916Z (about 1 year ago)
- Language: Swift
- Size: 4.88 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SwiftDataUIKit
## Description
SwiftData extensions for UIKit.
## Installation
To integrate a package into your Swift project using Swift Package Manager, add the package's URL to your `Package.swift` file as a dependency:
```swift
dependencies: [
.package(url: "https://github.com/noppefoxwolf/SwiftDataUIKit", from: "0.0.1")
]
```
# Usage
## Setup
Put @ViewQuery instead @Query in your view.
```swift
@ViewQuery(FetchDescriptor())
var users: [User]
```
ViewQuery need to load view and ModelContainer.
```swift
_users.load(view, modelContainer: modelContainer)
```
## Observe
`$users` is a Combine publisher. Any solution can be observe.
### Combine
```swift
$users.sink { ... }.store(in: $cancellables)
```
### Swift Concurrency
```swift
Task {
for await users in $users.values { ... }
}
```
## Mechanism
ViewQuery embeds QueryView when you call load().
QueryView is a SwiftUI view. That has a EmptyView and onChange modifier.
When the query is changed, the onChange modifier is called and publisher send.
# Required
- iOS 17+
# License
SwiftDataUIKit is available under the MIT license. See the LICENSE file for more info.