SwiftJsonUI 7.1.1 Release Notes - Tai-Kimura/SwiftJsonUI GitHub Wiki
August 27, 2025
SwiftJsonUI 7.1.1 introduces binding properties for custom components, enabling two-way data binding between parent and child components in SwiftUI mode.
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
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
}
]
}- ✅ 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
The Ruby converter detects @{propertyName} syntax and generates:
UserProfile(
user: $viewModel.data.currentUser,
isEditing: $viewModel.data.editMode,
showDetails: true
)The adapter creates proper SwiftUI bindings from the ViewModel:
let userBinding = Binding(
get: { viewModel.data.currentUser as? User ?? User() },
set: { viewModel.data.currentUser = $0 }
)- 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
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
No breaking changes. To use binding properties:
- Update Package.swift:
dependencies: [
.package(url: "https://github.com/Tai-Kimura/SwiftJsonUI.git", from: "7.1.1")
]- Start using binding properties:
sjui g converter MyComponent --attributes "@value:String,@isActive:Bool"- Use Bindings for Editable Data: Properties that users can modify should be bindings
- Static for Display-Only: Use regular properties for read-only data
- Consistent Naming: Use clear names that indicate the property's purpose
- Type Safety: Always specify the correct type for binding properties
- Documentation: SwiftJsonUI Wiki
- Issues: GitHub Issues
- Examples: Custom Components Examples
SwiftJsonUI is developed and maintained by Tai Kimura