← Back to ReactiveX/RxSwift

How to Deploy & Use ReactiveX/RxSwift

RxSwift Deployment and Usage Guide

Prerequisites

  • Swift: Version 5.0 or later
  • Platform: iOS 8.0+, macOS 10.10+, tvOS 9.0+, watchOS 2.0+, or Linux
  • Xcode: Version 11.0 or later (for iOS/macOS development)
  • CocoaPods: Version 1.0 or later (if using CocoaPods)
  • Carthage: Version 0.17 or later (if using Carthage)
  • Swift Package Manager: Included with Swift 5.0+ (if using SPM)

Installation

CocoaPods

  1. Add RxSwift to your Podfile:

    pod 'RxSwift', '~> 6.0'
    pod 'RxCocoa', '~> 6.0'
    
  2. Run the following command:

    pod install
    

Carthage

  1. Add RxSwift to your Cartfile:

    github "ReactiveX/RxSwift" ~> 6.0
    
  2. Run the following commands:

    carthage update
    
  3. Drag the built RxSwift.framework and RxCocoa.framework into your Xcode project.

Swift Package Manager

  1. In Xcode, select File > Add Packages...
  2. Enter the repository URL: https://github.com/ReactiveX/RxSwift.git
  3. Select the version or branch you want to use
  4. Add the package to your target

Manual Installation

  1. Clone the repository:

    git clone https://github.com/ReactiveX/RxSwift.git
    
  2. Drag the RxSwift.xcodeproj and RxCocoa.xcodeproj into your project

  3. Add the frameworks to your target's dependencies

Configuration

RxSwift doesn't require specific environment variables or API keys. However, you may need to:

  • Enable Background Modes (if using background operations)
  • Add Required Capabilities (if using specific features like Background Fetch)
  • Configure Info.plist (for any specific permissions or configurations)

Build & Run

Development

  1. Open your project in Xcode
  2. Ensure RxSwift and RxCocoa are added to your target's dependencies
  3. Build and run your project:
    xcodebuild -project YourProject.xcodeproj -scheme YourScheme -configuration Debug
    

Production

  1. Ensure you're using the release configuration:

    xcodebuild -project YourProject.xcodeproj -scheme YourScheme -configuration Release
    
  2. Archive your application for distribution

Deployment

iOS App Store

  1. Ensure your app meets App Store Review Guidelines
  2. Archive your app in Xcode
  3. Upload to App Store Connect
  4. Submit for review

macOS App Store

  1. Ensure your app meets Mac App Store Review Guidelines
  2. Archive your app in Xcode
  3. Upload to App Store Connect
  4. Submit for review

Enterprise Distribution

  1. Create an enterprise distribution certificate
  2. Archive your app with the enterprise certificate
  3. Distribute the IPA file to your enterprise devices

Testing

  • TestFlight: Use for beta testing with external testers
  • HockeyApp: Alternative beta testing platform
  • Firebase Test Lab: For automated testing on real devices

Troubleshooting

Common Issues

1. Build Errors with RxSwift

Problem: Xcode can't find RxSwift headers Solution:

  • Ensure RxSwift is properly added to your project
  • Check that the framework is included in your target's "Link Binary With Libraries" build phase
  • Verify the framework is in your target's "Framework Search Paths"

2. Runtime Errors

Problem: "dyld: Library not loaded: @rpath/RxSwift.framework/RxSwift" Solution:

  • Ensure the framework is properly embedded in your app bundle
  • Check that the "Embed Frameworks" build phase is correctly configured

3. Memory Leaks

Problem: Memory leaks when using RxSwift Solution:

  • Ensure you're properly disposing of subscriptions using DisposeBag
  • Use takeUntil or takeWhile to automatically dispose of subscriptions
  • Consider using weak references in closures to avoid retain cycles

4. Threading Issues

Problem: UI updates from background threads Solution:

  • Use observeOn(MainScheduler.instance) for UI updates
  • Use subscribeOn(ConcurrentDispatchQueueScheduler(qos: .background)) for background operations

5. Performance Issues

Problem: App becomes unresponsive with heavy Rx operations Solution:

  • Use observeOn to move operations to background threads
  • Use throttle or debounce to reduce the frequency of operations
  • Consider using share(replay: 1) to share subscriptions

Debugging Tips

  1. Print Statements: Use debug() operator to print events
  2. Breakpoints: Set breakpoints in RxSwift source code for deeper inspection
  3. Instruments: Use Xcode Instruments to profile memory and performance
  4. Unit Tests: Write comprehensive unit tests to catch issues early

Getting Help