File tree 2 files changed +11
-4
lines changed
2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change
1
+
2
+ ### Example C extension
3
+
4
+ Revised from [ Ben Snider's tutorial] ( https://www.bensnider.com/wrapping-c-code-within-a-single-swift-package.html )
Original file line number Diff line number Diff line change 1
1
import libadder
2
- protocol Addable {
2
+ public protocol Addable {
3
3
func add( _ x: Int , _ y: Int ) -> Int
4
4
}
5
5
6
6
public struct SimpleAdd : Addable {
7
- func add( _ x: Int , _ y: Int ) -> Int {
7
+ public init ( ) { }
8
+ public func add( _ x: Int , _ y: Int ) -> Int {
8
9
return libadder. add ( x, y)
9
10
}
10
11
}
11
12
12
13
public struct StructAdd : Addable {
13
- func add( _ x: Int , _ y: Int ) -> Int {
14
+ public init ( ) { }
15
+ public func add( _ x: Int , _ y: Int ) -> Int {
14
16
let op = add_operation ( x: x, y: y, result: 0 )
15
17
let result = libadder. added ( op)
16
18
return result. result;
17
19
}
18
20
}
19
21
20
22
public struct PointerAdd : Addable {
21
- func add( _ x: Int , _ y: Int ) -> Int {
23
+ public init ( ) { }
24
+ public func add( _ x: Int , _ y: Int ) -> Int {
22
25
var op = add_operation ( x: x, y: y, result: 0 )
23
26
libadder. adding ( & op)
24
27
return op. result;
You can’t perform that action at this time.
0 commit comments