You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+54-1Lines changed: 54 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,60 @@ Nitro Modules are highly efficient native modules exposed with a statically comp
20
20
21
21
## Usage
22
22
23
-
🤔
23
+
### 1. Create a TypeScript spec
24
+
25
+
The TypeScript spec is the single source of truth. It's interfaces, enums or other type declarations will be converted to C++ (or Swift/Kotlin) types using a code generator.
26
+
27
+
```ts
28
+
exportinterfaceMathsModule {
29
+
readonly pi:number
30
+
multiply: (a:number, b:number) =>number
31
+
subtract: (a:number, b:number) =>number
32
+
add: (a:number, b:number) =>number
33
+
}
34
+
```
35
+
36
+
### 2. Implement the native interface
37
+
38
+
In C++:
39
+
40
+
```cpp
41
+
classMathsModule: publicMathsModuleSpec {
42
+
public:
43
+
double getPi() override { return PI; }
44
+
45
+
double multiply(double a, double b) override { return a * b; }
46
+
double subtract(double a, double b) override { return a - b; }
47
+
double add(double a, double b) override { return a + b; }
48
+
};
49
+
```
50
+
51
+
In Swift:
52
+
53
+
```swift
54
+
class MathsModule: MathsModuleSpec {
55
+
var Pi: Double {
56
+
return .pi
57
+
}
58
+
59
+
func multiply(a: Double, b: Double) -> Double { return a * b }
60
+
func subtract(a: Double, b: Double) -> Double { return a - b }
61
+
func add(a: Double, b: Double) -> Double { return a + b }
62
+
}
63
+
```
64
+
65
+
In Kotlin:
66
+
67
+
```kotlin
68
+
classMathsModule: MathsModuleSpec {
69
+
valPi:Double
70
+
get() =PI
71
+
72
+
funmultiply(a:Double, b:Double): Double { return a * b }
73
+
funsubtract(a:Double, b:Double): Double { return a - b }
74
+
funadd(a:Double, b:Double): Double { return a + b }
0 commit comments