There are several options to integrate RxSwift and RxCocoa into an Xcode project. The README of the RxSwift project shows you the different possibilities. I mostly use CocoaPods and that is the approach I take in this series. If you would like to follow along with me, make sure you have CocoaPods installed. You can find more information about installing CocoaPods on the CocoaPods website.

Defining Dependencies

Open Terminal, navigate to the root of the project, and execute the pod init command to have CocoaPods create a Podfile for the project. Open the Podfile in a text editor and add RxSwift and RxCocoa as dependencies of the Cloudy target.

I also add RxTest and RxBlocking as dependencies of the CloudyTests target. These libraries are also part of the RxSwift project and are very helpful for testing reactive code. This is what the project's Podfile should look like.

target 'Cloudy' do
  platform :ios, '10.0'
  inhibit_all_warnings!
  use_frameworks!

  pod 'RxSwift'
  pod 'RxCocoa'

  target 'CloudyTests' do
    inherit! :search_paths

    pod 'RxTest'
    pod 'RxBlocking'
  end
end

Installing Dependencies

At the time of recording, RxSwift 5.1.1 is the latest release. Execute pod install to install the dependencies listed in the project's Podfile. CocoaPods automatically creates a workspace for us, which we need to use from now on.

Analyzing dependencies
Downloading dependencies
Installing RxBlocking (5.1.1)
Installing RxCocoa (5.1.1)
Installing RxRelay (5.1.1)
Installing RxSwift (5.1.1)
Installing RxTest (5.1.1)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `Cloudy.xcworkspace` for this project from now on.
Pod installation complete! There are 4 dependencies from the Podfile and 5 total pods installed.

Open the workspace CocoaPods created for us and build the project to make sure everything is working as expected. You should see no warnings or errors. The project is now ready to use RxSwift and RxCocoa. In the next episode, we refactor the AddLocationViewModel class.