SwiftJsonUI 7.1.1 Release Notes - Tai-Kimura/SwiftJsonUI GitHub Wiki

SwiftJsonUI 7.1.1 Release Notes

Release Date

August 27, 2025

Overview

SwiftJsonUI 7.1.1 introduces binding properties for custom components, enabling two-way data binding between parent and child components in SwiftUI mode.

✨ Key New Feature

Binding Properties for Custom Components

What's New

Custom components can now have binding properties that allow two-way data flow:

  • Prefix attribute names with @ when generating components to create binding properties
  • Use @{propertyName} syntax in JSON to bind to ViewModel data
  • Full support in both Static and Dynamic modes
  • Proper SwiftUI.Binding generation for type-safe bindings

How to Use

1. Generate a Component with Binding Properties:

sjui g converter UserProfile --attributes "@user:User,@isEditing:Bool,showDetails:Bool"

2. Generated Swift Component:

struct UserProfile<Content: View>: View {
    @SwiftUI.Binding var user: User        // Binding property
    @SwiftUI.Binding var isEditing: Bool   // Binding property
    let showDetails: Bool                  // Regular property
    let content: Content?
    
    init(
        user: SwiftUI.Binding<User>,
        isEditing: SwiftUI.Binding<Bool>,
        showDetails: Bool,
        @ViewBuilder content: () -> Content = { EmptyView() }
    ) {
        self._user = user
        self._isEditing = isEditing
        self.showDetails = showDetails
        self.content = content()
    }
    
    var body: some View {
        VStack {
            // Your custom UI here
            // Can read and write to binding properties
            TextField("Name", text: $user.name)
            Toggle("Edit Mode", isOn: $isEditing)
            if showDetails {
                Text("Details section")
            }
        }
    }
}

3. Use in JSON:

{
  "type": "UserProfile",
  "user": "@{currentUser}",      // Binds to $viewModel.data.currentUser
  "isEditing": "@{editMode}",     // Binds to $viewModel.data.editMode  
  "showDetails": true              // Static value (not a binding)
}

4. Define Data in Parent View:

{
  "data": [
    {
      "name": "currentUser",
      "class": "User",
      "defaultValue": {
        "name": "John Doe",
        "email": "[email protected]"
      }
    },
    {
      "name": "editMode",
      "class": "Bool",
      "defaultValue": false
    }
  ],
  "child": [
    {
      "type": "UserProfile",
      "user": "@{currentUser}",
      "isEditing": "@{editMode}",
      "showDetails": true
    }
  ]
}

Benefits

  • Two-Way Data Binding: Changes in child components automatically update parent state
  • 🔄 Reactive Updates: UI updates automatically when bound data changes
  • 🎯 Type Safety: Full Swift type checking for binding properties
  • 🚀 Performance: Efficient SwiftUI binding system with no overhead
  • 📦 Seamless Integration: Works with existing SwiftJsonUI data binding system

Technical Details

Static Mode

The Ruby converter detects @{propertyName} syntax and generates:

UserProfile(
    user: $viewModel.data.currentUser,
    isEditing: $viewModel.data.editMode,
    showDetails: true
)

Dynamic Mode

The adapter creates proper SwiftUI bindings from the ViewModel:

let userBinding = Binding(
    get: { viewModel.data.currentUser as? User ?? User() },
    set: { viewModel.data.currentUser = $0 }
)

🐛 Bug Fixes

  • Fixed Ruby converter's handling of falsey boolean values (nil vs false)
  • Improved binding expression detection in converter generator
  • Enhanced adapter generation for proper SwiftUI.Binding support

📚 Documentation

Updated documentation includes:

  • Comprehensive binding property examples in Converter Command docs
  • Clear explanation of @ prefix syntax for attributes
  • JSON binding syntax @{propertyName} usage
  • Use cases for binding properties

🔄 Migration from 7.1.0

No breaking changes. To use binding properties:

  1. Update Package.swift:
dependencies: [
    .package(url: "https://github.com/Tai-Kimura/SwiftJsonUI.git", from: "7.1.1")
]
  1. Start using binding properties:
sjui g converter MyComponent --attributes "@value:String,@isActive:Bool"

💡 Best Practices

  1. Use Bindings for Editable Data: Properties that users can modify should be bindings
  2. Static for Display-Only: Use regular properties for read-only data
  3. Consistent Naming: Use clear names that indicate the property's purpose
  4. Type Safety: Always specify the correct type for binding properties

📬 Support


SwiftJsonUI is developed and maintained by Tai Kimura

⚠️ **GitHub.com Fallback** ⚠️