How to make init with closure in Swift

Issue #526

1
2
3
4
5
6
7
public class Build: UsesXcodeBuild {
public var arguments = [String]()

public init(_ closure: (Build) -> Void = { _ in }) {
closure(self)
}
}

Use function builder

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class Workflow {
public var workingDirectory: String = "."
public let tasks: [Task]

public init(@TaskBuilder builder: () -> [Task]) {
self.tasks = builder()
self.tasks.forEach { task in
task.workflow = self
}
}

public init(@TaskBuilder builder: () -> Task) {
self.tasks = [builder()]
self.tasks.forEach { task in
task.workflow = self
}
}
}

public func run(@TaskBuilder builder: () -> [Task]) {
let workflow = Workflow(builder: builder)
workflow.run()
}

public func run(@TaskBuilder builder: () -> Task) {
let workflow = Workflow(builder: builder)
workflow.run()
}

Comments