项目集成ReactiveCocoa遇到的坑及解决办法

时间:2023-03-10 00:11:35
项目集成ReactiveCocoa遇到的坑及解决办法

  首先,使用CocoaPods集成(注意:由于ReactiveCocoa需要iOS8.0,并且是与swift混编的,所以Podfile文件要写成platform :ios, '8.0' 和 use_frameworks!),单集成没问题,但项目里用到SSKeychain,只要用到use_frameworks!总是报SSKeychain重复,把SSKeychain摘出来不用cocoaPods管理也是不行。

  于是用第二套方案:GitHub上官方提供的方法:

To add RAC to your application:

  1. Add the ReactiveCocoa repository as a submodule of your application’s repository.
  2. Run script/bootstrap from within the ReactiveCocoa folder.
  3. Drag and drop ReactiveCocoa.xcodeproj and Carthage/Checkouts/Result/Result.xcodeproj into your application’s Xcode project or workspace.
  4. On the “General” tab of your application target’s settings, add ReactiveCocoa.framework and Result.framework to the “Embedded Binaries” section.
  5. If your application target does not contain Swift code at all, you should also set the EMBEDDED_CONTENT_CONTAINS_SWIFTbuild setting to “Yes”.

补充:

  1、2两步请参考这里,3、4、5跟着做就好。然后build,会报错:

(null): error: /Users/xianfx/Documents/优化/XinfuPlatform/external/ReactiveCocoa/Carthage/Checkouts/Result/build/Debug-iphoneos/Result.framework: No such file or directory

(null): error: /Users/xianfx/Documents/优化/XinfuPlatform/external/ReactiveCocoa/build/Debug-iphoneos/ReactiveCocoa.framework: No such file or directory

解决办法是:找到项目的.xcodeproj文件 -> 显示包内容 -> 打开 project.pbxproj 文件,找到对应路径,删除即可。

  使用,又报错:

dyld: Library not loaded: @rpath/libswiftCore.dylib

  Referenced from: /Users/xianfx/Library/Developer/Xcode/DerivedData/XinfuPlatform-fsgkjtwplnourtaicvecgysbcqhq/Build/Products/Debug-iphonesimulator/ReactiveCocoa.framework/ReactiveCocoa

  Reason: image not found

好吧,中间停了好久没搞了,今天又试了下,看到了这个记录,解决了:targets -> BuildSettings ->Embedded Content Contains Swift code 设置成YES。

仅供参考!