Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit a9fdf0e

Browse files
author
Riccardo Cipolleschi
committed
[Setup] add Swift files
1 parent 7ec3849 commit a9fdf0e

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ Start from there up to the `[TurboModule] Test the Turbomodule` section. Then, f
77

88
* [[Setup] Update to 0.71-RC.3](#update)
99
* [[Setup] Update podspec](#update-podspec)
10-
10+
* [[Swift] Add Swift files](#swift)
1111

1212
## Steps
1313

14-
### <a name="update">[[Setup] Update to 0.71-RC.3]()
14+
### <a name="update" />[[Setup] Update to 0.71-RC.3]()
1515

1616
1. `cd NewArchitecture` - It has been created in this [step](https://github.com/react-native-community/RNNewArchitectureLibraries/tree/feat/back-turbomodule-070#tm-test).
1717
2. `yarn add react-native@0.71.0-rc.3`
1818

19-
### <a name="update-podspec">[[Setup] Update podspec]()
19+
### <a name="update-podspec" />[[Setup] Update podspec]()
2020

2121
1. Open the `calculator/calculator.podspec` file
2222
2. Update it as it follows:
@@ -64,3 +64,26 @@ Pod::Spec.new do |s|
6464
- end
6565
end
6666
```
67+
68+
### <a name="swift" />[[Swift] Add Swift files]()
69+
70+
1. Create a new file: `calculator/ios/calculator-Bridging-Header.h` with the following content
71+
```c++
72+
//
73+
// Add the Objective-C headers that must imported by Swift files
74+
//
75+
```
76+
**Note:** This file is used to specify some headers files that the Swift code should be able to import. For this example, it will stay empty. However, it is required to properly build the project.
77+
2. Create a new file `calculator/ios/Calculator.swift` with the implementation of the logic:
78+
```swift
79+
import Foundation
80+
81+
@objc
82+
class Calculator: NSObject {
83+
84+
@objc
85+
static func add(a: Int, b: Int) -> Int {
86+
return a+b;
87+
}
88+
}
89+
```

calculator/ios/Calculator.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Foundation
2+
3+
@objc
4+
class Calculator: NSObject {
5+
6+
@objc
7+
static func add(a: Int, b: Int) -> Int {
8+
return a+b;
9+
}
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//
2+
// Add the Objective-C headers that must imported by Swift files
3+
//

0 commit comments

Comments
 (0)