Cannot initialize a parameter of type 'NSArray> *' with an lvalue of type 'NS...

RN项目 iOS

升级xcode 14.5后,编译失败.

报错:
Cannot initialize a parameter of type 'NSArray> *' with an lvalue of type 'NSArray *__strong'

image.png

或者这个错误提示: No matching function for call to 'RCTBridgeModuleNameForClass'

解决办法

把这段代码添加到 Podfile:

post_install do |installer|
## Fix for XCode 12.5
     find_and_replace("../node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm",
    "_initializeModules:(NSArray> *)modules", "_initializeModules:(NSArray *)modules")
    find_and_replace("../node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm",
    "RCTBridgeModuleNameForClass(module))", "RCTBridgeModuleNameForClass(Class(module)))")
end

在 Podfile 的结尾添加这个方法:

def find_and_replace(dir, findstr, replacestr)
  Dir[dir].each do |name|
      text = File.read(name)
      replace = text.gsub(findstr,replacestr)
      if text != replace
          puts "Fix: " + name
          File.open(name, "w") { |file| file.puts replace }
          STDOUT.flush
      end
  end
  Dir[dir + '*/'].each(&method(:find_and_replace))
end

最后 iOS目录下执行pod install

你可能感兴趣的:(Cannot initialize a parameter of type 'NSArray> *' with an lvalue of type 'NS...)