如何正确安装“RxSwift”模块?

Posted

技术标签:

【中文标题】如何正确安装“RxSwift”模块?【英文标题】:how to properly install "RxSwift" module? 【发布时间】:2018-11-24 18:50:26 【问题描述】:

我正在尝试构建一个使用 RxSwift 模块的项目,XCode 一直抱怨错误“没有这样的模块 RxSwift”...

我试过多次安装这个模块,在终端我在pod install之后收到以下消息

    Analyzing dependencies
Downloading dependencies
Using RxCocoa (4.3.1)
Using RxSwift (4.3.1)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.

[!] Automatically assigning platform `ios` with version `11.4` on target `BTCPrice` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.

[!] Automatically assigning platform `watchos` with version `4.3` on target `WatchApp` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.

[!] Automatically assigning platform `watchos` with version `4.3` on target `WatchApp Extension` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.

[!] The `BTCPriceTests [Debug]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-BTCPriceTests/Pods-BTCPriceTests.debug.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

[!] The `BTCPriceTests [Release]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-BTCPriceTests/Pods-BTCPriceTests.release.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

据我了解,RxSwift 已安装,为什么 Xcode 一直抱怨它?

我正在执行 .xcworkspace 文件..

提前感谢您的回答!

【问题讨论】:

对,应该已经将 RxSwift 添加到您的工作区,但您是否已将 RxSwift 框架添加到实际项目的目标(即作为嵌入式二进制和/或链接框架)? 我建议你做 pod 工具建议的事情。 【参考方案1】:

How to remove CocoaPods from a project?

安装 pod 文件的简单步骤:

关闭 Xcode 项目

1.打开终端(Command + Space & type终端)

2.在终端设置你的项目路径。(cd Desktop/PodDemos)

3.终端输入命令:sudo gem install cocoapods

4.Command : pod init

5.转到项目的pod文件并添加要安装的pod(命令:打开podfile

6.添加到 pod 文件中:pod 'RxSwift'

pod 'RxCocoa'

7.Command : Pod install

8.从终端打开你的项目 命令:打开 PodDemos.xcworkspace

转到项目文件夹并打开 PodDemos.xcworkspace

【讨论】:

以上是关于如何正确安装“RxSwift”模块?的主要内容,如果未能解决你的问题,请参考以下文章

如何从 RxSwift 中的 onNext 获得正确的值?

正确使用 RxSwift 和 TableView

RxSwift 正确使用变量

如何正确地将 3rd 方库委托转换为 RxSwift Observable

RxSwift - onError 发出两次

在 RxSwift 4.0.0 中正确使用 retryWhen 运算符