Transform react-native AppDelegate.mm to AppDelegate.swift
- Get link
- X
- Other Apps
- Delete AppDelegate.h, AppDelegate.mm, main.m
- Make AppDelegate.swift & bridging-header
- Thankfully most of codes is wraped in RCTAppDelegate after RN0.71. So, as you can see, we should transform few codes from objective c to swift like below
There is a you can’t just copy and paste.
self.moduleName must be your ‘Project Name’
After making your own AppDelegate.swift and bridging-header, try to run using ‘npx react-native run-ios’ or ‘yarn ios’ wthatever you want. Then you can see this error.
In left, Project navigator displays, click your project > Build Settings > search ‘active com’
You can find Active Compilation Conditions. Add ‘DEBUG’ in Debug. It makes preprocessor recognize DEBUG flag.
Run your application again after adding DEBUG flag.
If you won’t use new architecture, this is it.
To run this app suing new architecture, run the following in ios directory.
bundle install && RCT_NEW_ARCH_ENABLED=1 bundle exec pod install
If you run after pod install, you will face the other error. Swift can’t recognize RCT_NEW_ARCH_ENABLED yet. So like we add DEBUG flag, let’s add RCT_NEW_ARCH_ENABLED flag.
Now xcode says the other error “Method does not override any method from its superclass”
Let’s go to RCTAppDelegate.h
You can see - (UIViewController *)createRootViewController; in #if RCT_NEW_ARCH_ENABLED block.
Take it out from the block
- Get link
- X
- Other Apps
Comments
Post a Comment