I have a react native sdk inside which all of the code is written in objective C, now we are migrating it to swift, i followed the official react native guide on how to migrate to swift, did everything as suggested there but it’s not working, i will explain where the main problem is happening –
so inside my objective c file my code is written like this –
#import <React/RCTBridgeModule.h>
#import <SCDoorway/SCDoorway.h>
#import <SCDoorway/SCDoorway-Swift.h>
#import <Loans/Loans.h>
#import <React/RCTBridge.h>
@interface RCT_EXTERN_MODULE(BigTreeDoorway, NSObject)
//MARK: SDK version helpers
//MARK: SDK setup
RCT_REMAP_METHOD(setConfigEnvironment,
envName:(NSString *)envName
gateway:(NSString *)gateway
isLeprechaunActive: (BOOL *)isLeprechaunActive
isAmoEnabled: (BOOL *)isAmoEnabled
preProvidedBrokers: (NSArray *)preProvidedBrokers
setConfigEnvironmentWithResolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
NSInteger environment = EnvironmentProduction;
if([envName isEqualToString:@"production"]) {
environment = EnvironmentProduction;
}
else if([envName isEqualToString:@"development"]) {
environment = EnvironmentDevelopment;
} else {
environment = EnvironmentStaging;
}
GatewayConfig *config = [[GatewayConfig alloc]
initWithGatewayName:gateway
brokerConfig:preProvidedBrokers
apiEnvironment:environment
isLeprechaunActive:isLeprechaunActive
isAmoEnabled:isAmoEnabled];
[SCDoorway.shared setupWithConfig: config completion:^(BOOL success,NSError * error) {
if(success) {
resolve(@(YES));
} else {
NSMutableDictionary *responseDict = [[NSMutableDictionary alloc] init];
[responseDict setValue:[NSNumber numberWithInteger:error.code] forKey:@"errorCode"];
[responseDict setValue:error.domain forKey:@"errorMessage"];
NSError *err = [[NSError alloc] initWithDomain:error.domain code:error.code userInfo:responseDict];
reject(@"setConfigEnvironment", @"Env setup failed", err);
}
}];
}
//and many more functions ...
now even in my objective-C file when i open up the xcode project of my SDK it gives me errors like –
now if i comment out that particular import it starts to give me error for –
but then inside the podspec file of my react sdk i have added the dependency SCDoorway –
moving on, when i build my react project it all builds well, and functions work
i started migrating to swift by adding a swift file with the same name as my objective-C file that is – BigTreeDoorway, so now i have 3 files in total inside my project which are the bridging header class, and BigTreeDoorway.swift and BigTreeDoorway.m
i have checked my objective c bridging header file path and it is alright
now when i converted all the objective functions to swift functions like this –
import RCTBridgeModule
import Foundation
import SCDoorway
import React
import Loans
@objc(BigTreeDoorway)
class BigTreeDoorway: NSObject {
@objc func setConfigEnvironment(_ envName: String,
gateway: String,
isLeprechaunActive: Bool,
isAmoEnabled: Bool,
preProvidedBrokers: [Any],
resolver resolve: @escaping RCTPromiseResolveBlock,
rejecter reject: @escaping RCTPromiseRejectBlock) {
var environment = EnvironmentProduction
switch envName {
case "production":
environment = EnvironmentProduction
case "development":
environment = EnvironmentDevelopment
default:
environment = EnvironmentStaging
}
let config = GatewayConfig(gatewayName: gateway,
brokerConfig: preProvidedBrokers,
apiEnvironment: environment,
isLeprechaunActive: isLeprechaunActive,
isAmoEnabled: isAmoEnabled)
SCDoorway.shared.setup(with: config) { success, error in
if success {
resolve(true)
} else {
var responseDict: [String: Any] = [
"errorCode": error?.code ?? 0,
"errorMessage": error?.localizedDescription ?? ""
]
let err = NSError(domain: error?.domain ?? "", code: error?.code ?? 0, userInfo: responseDict)
reject("setConfigEnvironment", "Env setup failed", err)
}
}
}
and then i changed my objectiveC file like this –
#import <React/RCTBridgeModule.h>
#import <SCDoorway/SCDoorway.h>
#import <SCDoorway/SCDoorway-Swift.h>
#import <Loans/Loans.h>
#import <React/RCTBridge.h>
@interface RCT_EXTERN_MODULE(BigTreeDoorway, NSObject)
RCT_EXTERN_METHOD(setConfigEnvironment,
envName:(NSString *)envName
gateway:(NSString *)gateway
isLeprechaunActive: (BOOL *)isLeprechaunActive
isAmoEnabled: (BOOL *)isAmoEnabled
preProvidedBrokers: (NSArray *)preProvidedBrokers
setConfigEnvironmentWithResolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
//many more
@end
basically i changed it to a RCT_EXTERN_METHOD from RCT_REMAP_METHOD and removed the function definition just the name and params as described in the react native site
i was still getting errors inside xcode for these imports –
but then the same was happening inside objectiveC file so i tried building my react project and it won’t build now, once it starts building the app after 30 seconds it gives me this error –
The following build commands failed:
SwiftCompile normal arm64 Compiling BigTreeDoorway.swift /Users/aadityasingh/../../../node_modules/my-sdk-name/ios/BigTreeDoorway.swift (in target 'my-sdk-name' from project 'Pods')
SwiftCompile normal arm64 /Users/aadityasingh/../../my sample app name where am trying to integrate the sdk/node_modules/my-sdk-name/ios/BigTreeDoorway.swift (in target 'my-sdk-name' from project 'Pods')
(2 failures)
Am stuck on this problem for the last two weeks now, i don’t understand how does the objective file works with the same imports but my swift file fails to do so, please help, i tried few things –
- I tried changing the "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 i386"
inside both the sample app, later i tried it with the my sdk ios project too
the build error was still there - i deleted the xcode project from ios folder of the my sdk and the sample app still works perfectly fine, hence only 3 files left – bridging header, swift (swift file being empty with just the class defined) and objc file
- when i import Loans (which is a submodule inside SCDoorway) inside the swift file of my sdk, it does not throw any error and the react project builds but then when i uncomment it’s functions which involve using Loans classes (and then i put the RCT_EXTERN_METHODS for the same inside objectiveC class commenting everything else out) it throws another error –
The following build commands failed:
CompileC /Users/aadityasingh/Library/Developer/Xcode/DerivedData/sample-app-name-dnrqbqkvgavrbjasjmzapzzrvjtq/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/my-sdk-name.build/Objects-normal/arm64/BigTreeDoorway-5f1feec19880e569a1329e3d7cbede9a.o /Users/aadityasingh/../new/sample app name/node_modules/sdk name/ios/BigTreeDoorway.m normal arm64 objective-c com.apple.compilers.llvm.clang.1_0.compiler (in target 'my-sdk-name' from project 'Pods')
(1 failure)
Please help me with this
2
Answers
changing -
inside Pods project and
inside iOS app project of my app compiles the code. hope this helps anyone facing the same issue
When I finally figured out what was wrong, it had to do with the version of the pod that the code was using.
Therefore, if you’re still having these problems, I advise you to:
OR
support for arm64
verify if the issue persists
OR
Visit this links :