✨ New Features
DictionaryBuilder
Complete result builder for type-safe dictionary construction with:
- Tuple syntax:
("key", "value")for simple key-value pairs - KeyValuePair helper:
KeyValuePair("key", "value")for better readability - Dictionary merging: Seamlessly merge existing dictionaries
- Full control flow: Support for
if/else, loops, and optionals - Key conflict resolution: "Last writer wins" semantics
- Type safety: Generic
<Key: Hashable, Value>with full type inference
let config = Dictionary<String, String> {
("host", "localhost")
("port", "8080")
if enableSSL {
("ssl", "true")
("cert_path", "/path/to/cert.pem")
}
existingConfig // merge existing dictionary
}🔄 Improvements
ArrayBuilder Modernization
Updated to use modern buildPartialBlock methods:
- Better performance: More efficient compilation and runtime
- Consistent architecture: Aligns with other builders in the package
- Hybrid approach: Combines buildPartialBlock efficiency with buildExpression type safety
- Full compatibility: All existing code continues to work unchanged
📚 Documentation
- Comprehensive README updates with DictionaryBuilder examples
- Real-world usage patterns including Dynamic Configuration System example
- Updated architecture documentation showing all five builders
- Production-ready examples for common use cases
🧪 Testing
- 112 comprehensive tests covering all builders and edge cases
- Full test coverage for DictionaryBuilder functionality
- Verified compatibility - all existing functionality preserved
- Performance testing with large datasets
🏗️ Complete Architecture
swift-builders now provides a complete result builder ecosystem:
swift-builders
├── ArrayBuilder → Generic array construction (modernized)
├── DictionaryBuilder → Key-value pair construction (new)
├── SetBuilder → Unique element collections
├── StringBuilder → Text content generation
└── MarkdownBuilder → Documentation and markup
🚀 Getting Started
Installation
Add to your Package.swift:
dependencies: [
.package(url: "https://github.com/coenttb/swift-builders.git", from: "0.1.0")
]Quick Example
import ArrayBuilder
import DictionaryBuilder
import SetBuilder
// Build arrays declaratively
let menuItems = Array<String> {
"Home"
"About"
if user.isAuthenticated {
"Dashboard"
"Profile"
}
}
// Create configuration dictionaries
let serverConfig = Dictionary<String, String> {
("host", "localhost")
("port", "8080")
if isProduction {
("ssl", "true")
}
}
// Build unique collections
let permissions = Set<Permission> {
.read
.write
if user.isAdmin {
[.admin, .delete]
}
}🎯 What's Next
This release completes the core collection builder suite. Future releases will focus on:
- Performance optimizations
- Additional convenience methods
- Enhanced error handling
- More real-world examples
💬 Support
- 📚 Documentation
- 🐛 Issues
- 💡 Discussions
Full Changelog: 0.0.1...0.1.0