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

Commit 9d5ee1a

Browse files
author
Riccardo Cipolleschi
committed
[iOS] Update calculator files
1 parent a9fdf0e commit 9d5ee1a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Start from there up to the `[TurboModule] Test the Turbomodule` section. Then, f
88
* [[Setup] Update to 0.71-RC.3](#update)
99
* [[Setup] Update podspec](#update-podspec)
1010
* [[Swift] Add Swift files](#swift)
11+
* [[iOS] Update Calculator file](#update-calculator)
1112

1213
## Steps
1314

@@ -87,3 +88,28 @@ end
8788
}
8889
}
8990
```
91+
92+
### <a name="upadet-calculator" />[[iOS] Update Calculator file]()
93+
94+
1. Open the `calculator/ios/RNCalculator.mm` file and update the logic to invoke the Swift one
95+
```diff
96+
#ifdef RCT_NEW_ARCH_ENABLED
97+
#import "RNCalculatorSpec.h"
98+
#endif
99+
100+
+ #import "calculator-Swift.h"
101+
102+
@implementation RNCalculator
103+
104+
RCT_EXPORT_MODULE(Calculator)
105+
106+
RCT_REMAP_METHOD(add, addA:(NSInteger)a
107+
andB:(NSInteger)b
108+
withResolver:(RCTPromiseResolveBlock) resolve
109+
withRejecter:(RCTPromiseRejectBlock) reject)
110+
{
111+
- NSNumber *result = [[NSNumber alloc] initWithInteger:a+b];
112+
+ NSNumber *result = @([Calculator addWithA:a b:b]);
113+
resolve(result);
114+
}
115+
```

calculator/ios/RNCalculator.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#import "RNCalculatorSpec.h"
55
#endif
66

7+
#import "calculator-Swift.h"
8+
79
@implementation RNCalculator
810

911
RCT_EXPORT_MODULE()
@@ -26,7 +28,7 @@ @implementation RNCalculator
2628
#endif
2729

2830
- (void)add:(double)a b:(double)b resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
29-
NSNumber *result = [[NSNumber alloc] initWithInteger:a+b];
31+
NSNumber *result = @([Calculator addWithA:a b:b]);
3032
resolve(result);
3133
}
3234

0 commit comments

Comments
 (0)