swift-builder

1.1.0

Builder Patterns for Flexible Syntax in Swift.
pelagornis/swift-builder

What's New

1.1.0

2024-06-01T16:49:20Z

What's Changed

  • Added: Macro feature abililty from swift 5.9 package
  • Updated: BuilderCompatible to Buildable

Builder

Official SPM Swift License Platform

Builder Patterns for Flexible Syntax in Swift

Installation

Builder was deployed as Swift Package Manager. Package to install in a project. Add as a dependent item within the swift manifest.

let package = Package(
    ...
    dependencies: [
        .package(url: "https://github.com/pelagornis/swift-builder.git", from: "1.1.0")
    ],
    ...
)

Then import the Builder from thr location you want to use.

import Builder

And then adding the product to any target that needs access to the library:

.product(name: "Builder", package: "swift-builder"),

Documentation

The documentation for releases and main are available here:

Using

Initializer UIView with Builder

let view = UIView()
    .builder()
    .translatesAutoresizingMaskIntoConstraints(false)
    .backgroundColor(.systemBlue)
    .build()

This is equivalent to

let view: UIView = {
    let view = UIView()
    view.translatesAutoresizingMaskIntoConstraints = false
    view.backgroundColor(.systemBlue)
    return view
}()

Want to use with your own types? Just make extensions.

extension MyType: Buildable {}

let instance = MyType()
    .builder()
    .property("some value")
    .build()

Support Macros

Starting with Swift version 5.9, @Builder macro is supported.

@Builder
struct Pelagornis {
    var libraryName: String?
}

License

Builder is under MIT license. See the LICENSE file for more info.

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Sun Nov 03 2024 23:20:54 GMT-1000 (Hawaii-Aleutian Standard Time)