Welcome to the documentation for RxDisplayLink, a reactive wrapper around CADisplayLink for iOS, macOS, tvOS, and watchOS. RxDisplayLink provides a simple and intuitive way to use CADisplayLink with reactive programming and is built on top of the popular RxSwift library.
To install RxDisplayLink, you can use CocoaPods by adding the following line to your Podfile:
pod 'RxDisplayLink'
Alternatively, you can manually include the necessary files in your project.
Getting started with RxDisplayLink is quick and easy. Follow the steps below:
Step 1: Import Statements
In the file where you’ll be using RxDisplayLink, add the following import statement at the top:
import RxDisplayLink
Step 2: Create an Instance
You’ll need to create an instance of RxDisplayLink to use it in your project. Here’s an example:
let displayLink = RxDisplayLink()
Step 3: Subscribe to Updates
To receive updates from the CADisplayLink, subscribe to the displayLink’s displayLinkUpdates
property. Here’s an example:
displayLink.displayLinkUpdates
.subscribe(onNext: { timestamp in
// Update UI or perform other actions
})
.disposed(by: disposeBag)
RxDisplayLink provides a number of methods and properties to enhance your usage of CADisplayLink. Here are some of the most commonly used ones:
displayLinkUpdates
A reactive property that emits the timestamp of each display refresh. Subscribe to this property to receive updates from the CADisplayLink.
subscribe(onNext:)
Subscribes to the displayLinkUpdates
property and performs the provided closure when a value is emitted.
disposeBag
A bag to dispose of the subscription when it is no longer needed. Add the disposable to the dispose bag using disposed(by:)
method.
Here are some additional resources to further explore and enhance your understanding of RxDisplayLink:
GitHub Repository
Visit the RxDisplayLink GitHub repository for the latest updates, code examples, and issues: RxDisplayLink GitHub.
RxSwift Documentation
Consult the official RxSwift documentation for more information on reactive programming and usage: RxSwift Documentation.
Sample Code
Check out the RxDisplayLink sample code to see concrete examples of how to integrate RxDisplayLink into your project effectively: RxDisplayLink Sample Code.
Congratulations! You have now learned the basics of using RxDisplayLink and integrating it into your iOS, macOS, tvOS, or watchOS project. Feel free to explore the additional resources and experiment with the library to enhance your reactive programming experience.