Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tokijh/ViewCondition
✨ Super sweet syntactic sugar for SwiftUI.View initializers.
https://github.com/tokijh/ViewCondition
Last synced: about 2 months ago
JSON representation
✨ Super sweet syntactic sugar for SwiftUI.View initializers.
- Host: GitHub
- URL: https://github.com/tokijh/ViewCondition
- Owner: tokijh
- License: mit
- Created: 2021-09-30T13:19:17.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-09-30T14:28:26.000Z (over 3 years ago)
- Last Synced: 2024-11-15T04:32:12.465Z (about 2 months ago)
- Language: Swift
- Size: 3.91 KB
- Stars: 96
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-swiftui-libraries - ViewCondition - Super sweet syntactic sugar for SwiftUI.View initializers. (Extensions / Content)
README
# ViewCondition
✨ Super sweet syntactic sugar for SwiftUI.View initializers.
## At a Glance
```swift
struct BorderTextView: View {
var color: Color?@ViewBuilder
var body: some View {
Text("Hello")
.if(let: color) {
$0.border($1)
}
}
}
```This is equivalent to:
```swift
struct BorderTextView: View {
var color: Color?@ViewBuilder
var body: some View {
let text = Text("Hello")
if let color = color {
text.border(color) // border doesn't allow optional
} else {
text
}
}
}
```## Operators
### if let
```swift
let color: Color?
Text("Hello")
.if(let: color) {
$0.border($1)
}
```### if
```swift
let text = ""
Text("Hello")
.if(text == "Hello") {
$0.bold()
}
```### ifNot
```swift
let text = ""
Text("Hello")
.ifNot(text == "Hello") {
$0.bold()
}
```### then
```swift
let text = ""
Text("Hello")
.then {
if text == "Hello" {
$0.bold()
} else {
$0.italic()
}
}
```#### ⚠️ Becareful
**If you don't return view in `else`, the view may not come out.**
## Installation
Using Swift Package Manager:
```swift
import PackageDescriptionlet package = Package(
name: "MyAwesomeApp",
dependencies: [
.package(url: "https://github.com/tokijh/ViewCondition.git", from: "1.0.0")
]
)
```## Special thanks to..
- [@leedh2004](https://github.com/leedh2004)## License
**ViewCondition** is under MIT license. See the [LICENSE](LICENSE) file for more info.