Skip to content

Releases: Aeastr/Conditionals

1.2.3

14 Jan 20:39

Choose a tag to compare

Remove Icon file from git tracking

1.2.2

14 Jan 20:33

Choose a tag to compare

Lower swift-tools-version to 6.0 for CI compatibility

v1.2.1

14 Jan 04:20

Choose a tag to compare

Documentation

  • Revamp README with improved structure
  • Add ViewIdentity.md documentation
  • Add WhenToUse.md usage guidance
  • Update icon assets

1.2.0 - Conditionals Protocol

06 Nov 13:47

Choose a tag to compare

1.1.0 - Initial Release

28 Oct 18:39

Choose a tag to compare

Conditionals is a lightweight SwiftUI package that provides clean, composable conditional modifier APIs for handling OS availability checks. This is the first public release.

🎯 What is Conditionals?

Stop cluttering your SwiftUI views with nested #available checks and complex branching logic. Conditionals gives you a fluent, chainable API that keeps your code clean and readable while safely handling OS version differences.

✨ Features

View Extensions

Apply modifiers conditionally with a clean, SwiftUI-native API:

Text("Hello")
    .conditional(if: OSVersion.iOS(26)) { view in
        view.fontWeight(.semibold)
    }
    .conditional { view in
        if #available(iOS 26.0, *) {
            view.glassEffect(.regular, in: .rect(cornerRadius: 12))
        } else if #available(iOS 18.0, *) {
            view.background(.regularMaterial, in: .rect(cornerRadius: 12))
        } else {
            view.background(Color.gray.opacity(0.3))
        }
    }

Available methods:

  • .conditional(if:apply:) - Basic conditional
  • .conditional(if:apply:otherwise:) - With fallback
  • .conditional(apply:) - Closure variant for full control
  • .conditional(if:apply:) - Optional unwrapping variant
  • .conditional(unless:apply:) - Negated variant

ToolbarContent Extensions

All View conditional methods work seamlessly with ToolbarContent:

ToolbarItem(placement: .topBarTrailing) {
    Button("Action") {}
        .conditional(if: OSVersion.iOS(26)) { view in
            view.tint(.blue)
        }
}

ToolbarItemPlacement Extensions

Choose toolbar item placement conditionally:

ToolbarItemGroup(
    placement: .conditional(
        if: OSVersion.iOS(26),
        then: .bottomBar,
        else: .secondaryAction
    )
) {
    Button("Edit") {}
    Button("Share") {}
}

Or use the closure variant for complex checks:

ToolbarItemGroup(
    placement: .conditional {
        if #available(iOS 26.0, *) {
            .bottomBar
        } else {
            .secondaryAction
        }
    }
) {
    Button("Edit") {}
}

OS Version Helpers

Runtime version checking made simple:

// Check specific versions
OSVersion.iOS(26)       // Check iOS 26+
OSVersion.macOS(26)     // Check macOS 26+
OSVersion.watchOS(26)   // Check watchOS 26+
OSVersion.tvOS(26)      // Check tvOS 26+

// Convenience helpers
OS.is26                           // Quick boolean check
OSVersion.supportsGlassEffect    // iOS 26+ check

📱 Platform Support

  • iOS 16.0+
  • visionOS 1.0+
  • macOS 13.0+
  • watchOS 9.0+
  • tvOS 16.0+
  • Swift 6.0+

🎨 Design Philosophy

Conditionals is designed for static conditions:

  • ✅ OS version checks (primary use case)
  • ✅ Compile-time #available checks
  • ✅ Static styling modifiers
  • ❌ Not recommended for runtime state that changes frequently

Using conditionals with runtime state that toggles can cause view identity loss and state resets. For dynamic content, use SwiftUI's built-in if, overlay, or background within view builders instead.

🔗 Related Packages

If you're working specifically with iOS 26's glass effects, check out UniversalGlass - a purpose-built solution that brings iOS 26 glass APIs to earlier deployments with lightweight shims. UniversalGlass uses Conditionals under the hood.

📦 Installation

Swift Package Manager

Add Conditionals to your project via Xcode or your Package.swift:

dependencies: [
    .package(url: "https://github.com/aeastr/Conditionals.git", from: "1.1.0")
]