https://github.com/Karumi/ControlFlowUI
A library that add control flow functionality to SwitUI, using the power of @functionBuilder and ViewBuilder.
https://github.com/Karumi/ControlFlowUI
Last synced: 19 days ago
JSON representation
A library that add control flow functionality to SwitUI, using the power of @functionBuilder and ViewBuilder.
- Host: GitHub
- URL: https://github.com/Karumi/ControlFlowUI
- Owner: Karumi
- License: apache-2.0
- Created: 2019-06-14T09:02:16.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-09-17T14:40:08.000Z (over 5 years ago)
- Last Synced: 2024-11-02T23:32:33.133Z (6 months ago)
- Language: Swift
- Homepage:
- Size: 18.6 KB
- Stars: 25
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-result-builders - ControlFlowUI - A library that add control flow functionality to SwitUI, using the power of `@functionBuilder` and `ViewBuilder` (SwiftUI)
README
# ControlFlowUI
A library that add control flow functionality to SwitUI, using the power of @functionBuilder and ViewBuilder.
When you get the following error message, check this library:
**❗Closure containing control flow statement cannot be used with function builder 'ViewBuilder'**
## Features
### Switch - Type-Casting Patterns
```swift
List(dogs.identified(by: \.name)) { dog in
SwitchValue(dog) {
CaseIs(Animal.self) { value in
Text(value.species)
}
CaseIs(Dog.self) { value in
Text(value.breed)
}
}
}
```### If Let - Optional Binding
```swift
struct DogDetailView : View {
@ObjectBinding
var viewModel: DogDetailViewModelvar body: some View {
IfLet(viewModel.dog) { item in
VStack {
Text(item.name).color(.white).padding()
Text(item.description).color(.white).lineLimit(nil).padding()
Spacer()
}
}
.onAppear {
self.viewModel.load()
}
}
}
```## Requirements
- iOS 13+ / macOS 10.15+ / tvOS 13+, watchOS 6+
- Xcode 11+
- Swift 5.1+## Installation
### XCode
1. File > Swift Packages > Add Package Dependency...
2. Choose Project you want to add ControlFlowUI
3. Paste repository URL https://github.com/Karumi/ControlFlowUI
4. Rules > Branch: Master### Swift Package Manager
```swift
dependencies: [
.package(url: "https://github.com/Karumi/ControlFlowUI.git", .branch("master"))
]
```