An open API service indexing awesome lists of open source software.

https://github.com/pelagornis/swift-builder

Builder Patterns for Flexible Syntax in Swift.
https://github.com/pelagornis/swift-builder

builder-design-pattern builder-pattern macro pelagornis swift

Last synced: 2 months ago
JSON representation

Builder Patterns for Flexible Syntax in Swift.

Awesome Lists containing this project

README

          

# Builder

![Official](https://badge.pelagornis.com/official.svg)
![SPM](https://img.shields.io/badge/SPM-compatible-brightgreen.svg)
![Swift](https://img.shields.io/badge/Swift-5.9-orange.svg)
[![License](https://img.shields.io/github/license/pelagornis/swift-builder)](https://github.com/pelagornis/swift-builder/blob/main/LICENSE)
![Platform](https://img.shields.io/badge/platforms-iOS%2013.0%7C%20tvOS%2013.0%7C%20macOS%2010.15%7C%20watchOS%206.0-red.svg)

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.
```swift
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.
```swift
import Builder
```
And then adding the product to any target that needs access to the library:

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

## Documentation
The documentation for releases and ``latest`` are available here:
- [``latest``](https://pelagornis.github.io/swift-builder/latest/documentation/builder)

## Using
Initializer UIView with ``Builder``

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

This is equivalent to

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

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

```swift
extension MyType: Buildable {}

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

## Support Macros
`@Builder` macro is supported.

```swift
@Builder
struct Pelagornis {
var libraryName: String?
}
```

## License
**Builder** is under MIT license. See the [LICENSE](LICENSE) file for more info.