You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何彻底移除iOS项目中的React Native,转为纯Swift项目?

Got it, let's walk through how to fully strip React Native out of your iOS project and convert it to pure Swift. I've gone through this process a few times, so here's a detailed, step-by-step breakdown that covers every corner to make sure nothing is left behind:

Step 1: Nuke React Native Dependencies from Your Podfile

First up, open your project's Podfile and delete all React Native-related pods. That includes things like React, React-Core, React-NativeModules, any third-party RN libraries you were using, and the use_react_native! line if you have it.

Once that's done, run these commands in your terminal (from the iOS project directory) to clean up:

pod deintegrate
pod install

This will remove all RN-related pods and rebuild your Pods directory with only the dependencies your pure Swift project needs.

Step 2: Clean Up Xcode Project Files & Configuration

Now let's fix the Xcode project itself:

  • Update AppDelegate.swift: Remove all React Native initialization code. Replace the part where you set up RCTRootView with your pure Swift root view controller—whether that's a UINavigationController, UIHostingController (for SwiftUI), or your custom main view controller.
  • Delete RN-specific resources: Remove files like main.jsbundle, RN-only Assets.xcassets, and any other RN-related asset files from your Xcode project. Make sure to select "Move to Trash" when deleting to remove them from the filesystem too.
  • Remove RN build phases: Go to your project's target > Build Phases. Delete the "Bundle React Native code and images" phase, and any other RN-specific build phases you might have added (like copying RN assets).
  • Clean Info.plist: Remove any RN-related entries, such as NSAppTransportSecurity exceptions added for local RN debugging, or custom URL schemes used for RN deep linking (if you don't need them anymore).
Step 3: Delete React Native Files from Your Project Directory

Head to your project's root folder (outside the iOS directory) and delete these RN-specific files/folders:

  • node_modules folder
  • package.json, yarn.lock, package-lock.json
  • metro.config.js, index.js, App.js (or your main RN entry files)
  • .babelrc, .eslintrc, or any other RN-related config files
  • If you have an unused android folder, you can delete that too.
Step 4: Hunt Down & Remove Remaining RN References

Even after the above steps, there might be leftover references. Do a full search in your Xcode project (use the top-right search bar, set to "Find in Project") for keywords like React, RCT, RN, or any RN library names you were using.

For each result:

  • Delete import statements for RN classes (like import React or import RCTRootView)
  • Remove any code that uses RN APIs or components
  • Check Build Settings: Go to your target > Build Settings, search for "Header Search Paths" and "Library Search Paths"—delete any paths pointing to React Native or its modules. Also, check "Other Linker Flags" and remove any flags related to RN (like -lReact).
Step 5: Verify & Clean Up

Finally:

  • Run Product > Clean Build Folder in Xcode to clear any cached RN build files
  • Build and run your project to make sure it works without crashes or errors
  • Double-check your project directory with a global search tool (like VS Code) to ensure no RN-related files or code snippets were missed

Pro tip: Before you start any of this, make a full backup of your project (or commit everything to Git with a clear message like "Pre-RN removal backup")—it's easy to accidentally delete something you need!

内容的提问来源于stack exchange,提问作者iHulk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 03:49:28