How to not use protocol extension in Swift

Issue #542

With protocol extension

See code Puma

1
Build is UsesXcodeBuild is UsesCommandLine
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/// Any task that uses command line
public protocol UsesCommandLine: AnyObject {}

public extension UsesCommandLine {
func runBash(
workflow: Workflow,
program: String,
arguments: [String],
processHandler: ProcessHandler = DefaultProcessHandler()
) throws {
// Code
}

func runProcess(
_ process: Process,
workflow: Workflow,
processHandler: ProcessHandler = DefaultProcessHandler()
) throws {
// Code
}
}

/// Any task that uses xcodebuild
public protocol UsesXcodeBuild: UsesCommandLine {
var xcodebuild: Xcodebuild { get set }
}

public extension UsesXcodeBuild {
func runXcodeBuild(workflow: Workflow) throws {
try runBash(
workflow: workflow,
program: "xcodebuild",
arguments: xcodebuild.arguments,
processHandler: XcodeBuildProcessHandler()
)
}
}

public class Build: UsesXcodeBuild {
public var isEnabled = true
public var xcodebuild = Xcodebuild()
}

Without protocol extension

1
Build has Xcodebuild has CommandLine
1
2
3
4
5
6
7
8
9
10
11
12
13
public struct Xcodebuild {
var arguments: [String] = []

@discardableResult
func run(workflow: Workflow) throws -> String {
return try CommandLine().runBash(
workflow: workflow,
program: "xcodebuild",
arguments: arguments,
processHandler: XcodeBuildProcessHandler()
)
}
}

Comments