ViewCondition – systamatic coding viewcontroller
  • July 15, 2025

✨ Super sweet syntactic sugar for SwiftUI.View initializers.

At a Glance


struct BorderTextView: View {
var color: Color?

@ViewBuilder
var body: some View {
Text(“Hello”)
.if(let: color) {
$0.border($1)
}
}
}

This is equivalent to:

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

let color: Color?
Text(“Hello”)
.if(let: color) {
$0.border($1)
}

if

let text = “”
Text(“Hello”)
.if(text == “Hello”) {
$0.bold()
}

ifNot

let text = “”
Text(“Hello”)
.ifNot(text == “Hello”) {
$0.bold()
}

then

 

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 Pacage Manager:

import PackageDescription

let package = Package(
name: “MyAwesomeApp”,
dependencies: [
.package(url: “https://github.com/tokijh/ViewCondition.git”, from: “1.0.0”)
]
)

GitHub


View Github

#uiviewcontroller
YOU MIGHT ALSO LIKE...
MijickPopups Hero

  Popups Alerts Resizable Sheets Banners

SwiftUI Tooltip

This package provides you with an easy way to show tooltips over any SwiftUI view, since Apple does not provide ...

SimpleToast for SwiftUI

SimpleToast is a simple, lightweight, flexible and easy to use library to show toasts / popup notifications inside iOS or ...

SSToastMessage

Create Toast Views with Minimal Effort in SwiftUI Using SSToastMessage. SSToastMessage enables you to effortlessly add toast notifications, alerts, and ...

ToastUI

A simple way to show toast in SwiftUI   Getting Started • Documentation • Change Log