Slide 1

Slide 1 text

A t t i a M o Quick Tips For Writing RxSwift. @AttiaMoTheDev

Slide 2

Slide 2 text

A t t i a M o !# @AttiaMoTheDev

Slide 3

Slide 3 text

A t t i a M o @AttiaMoTheDev $ Reactive Programming % & ReactiveX ' ( RxSwift ) * RxSwift ⌚﹠ - Community / Resources Agenda .

Slide 4

Slide 4 text

A t t i a M o @AttiaMoTheDev $ Reactive programming %.

Slide 5

Slide 5 text

A t t i a M o @AttiaMoTheDev https://en.wikipedia.org/wiki/Reactive_programming

Slide 6

Slide 6 text

A t t i a M o @AttiaMoTheDev

Slide 7

Slide 7 text

A t t i a M o @AttiaMoTheDev ⚫ “Data streams and the propagation of change”. ⚫ “Event Based Model”. ⚫ “Asnyc Sequence Of Events”.

Slide 8

Slide 8 text

A t t i a M o @AttiaMoTheDev & ReactiveX '

Slide 9

Slide 9 text

A t t i a M o @AttiaMoTheDev http://reactivex.io

Slide 10

Slide 10 text

A t t i a M o @AttiaMoTheDev http://reactivex.io

Slide 11

Slide 11 text

WHAT’S YOUR LANGUAGE? A t t i a M o @AttiaMoTheDev

Slide 12

Slide 12 text

A t t i a M o @AttiaMoTheDev ( RxSwift ⌚﹠

Slide 13

Slide 13 text

Why to use RxSwift? Benefits and use cases Synchronize two requests ⏬ However, despite the obvious powerful capabilities of KVO, the RXSwift creators solve this issue radically by minimizing the necessity to involve this API at all. Delegates required keeping in mind a huge amount of information, RxSwift managed to solve this problem completely. This library had introduced the ability to write code in the declarative style without increasing the size of the UIViewController and requiring the objc
 You’re bored of KVO/Delegates RP leads to writing less code. 
 Since you can react to events in a declarative way you can avoid certain complications. Like nested callbacks, delegates, notifications, etc. For example, in the previous login process.
 Since Rx streams are immutable, you can just react to changes and create objects that are open to extensions and closed to modifications.
 Rx in MVVM and other MVC improvements like VIPER. You can bind objects of different architecture layers and the architecture remains clean. Cleaner Code & Architectures. Providing the synchronization for the calls can be difficult even for an experienced developer.
 If you are using RxSwift, you can simply use a zip operator that would combine the two observables and send an answer at the end of processing two API requests. A t t i a M o @AttiaMoTheDev https://medium.com/@leandromperez/why-use-rxswift-a176b553a705
 https://applikeysolutions.com/blog/rxswift-benefits-and-use-cases

Slide 14

Slide 14 text

Why to use RxSwift? Benefits and use cases https://medium.com/@leandromperez/why-use-rxswift-a176b553a705
 https://applikeysolutions.com/blog/rxswift-benefits-and-use-cases Multi-threading is simplified. The structures provide different ways of publishing information. For instance, a PublishSubject or a BehaviorSubject. They are different ways of channeling events. The operations transform, decorate, compose, etc, the information. Like map, filter, concat, etc. The key is that everyone can use the same structures and operations. No matter what they put in them. Modular Code? Reactive programming is a way of working, it’s a design pattern, or a set of them for all that matters. You can create reusable compassable components because of the standard structures and operations. The same standardization comes in different languages and platforms. So If you learn Reactive Programming in Swift, you can take it with you to another platform and language. Multi-platform? Using RxSwift, you can react to changes on different threads. You do this with a lot less code, less complexity, less bugs. You can listen to an event on the main thread and react in background. Finally you can go back to the main thread to show the results. The resulting code can be very simple: you observeOn different Schedulers. A t t i a M o @AttiaMoTheDev

Slide 15

Slide 15 text

A t t i a M o @AttiaMoTheDev * RxSwift )

Slide 16

Slide 16 text

A t t i a M o @AttiaMoTheDev

Slide 17

Slide 17 text

Observables are the heart of Rx. You’re going to spend some time discussing what observables are, how to create them, and how to use them. What is an observable? Observables. A t t i a M o @AttiaMoTheDev

Slide 18

Slide 18 text

Lifecycle of an observable A t t i a M o @AttiaMoTheDev • An observable emits next events that contain elements. It can continue to do this until it either: • emits an error event and is terminated, or • emits a Completed event and is terminated. • Once an observable is terminated, it can no longer emit events. Observable Lifecycle

Slide 19

Slide 19 text

A t t i a M o @AttiaMoTheDev • An observable emits next events that contain elements. It can continue to do this until it either: • emits an error event and is terminated, or • emits a Completed event and is terminated. • Once an observable is terminated, it can no longer emit events. Observable Lifecycle

Slide 20

Slide 20 text

something that can act as both an observable and as an observer. And that something is called a Subject. What is Subjects? Subjects. A t t i a M o @AttiaMoTheDev

Slide 21

Slide 21 text

• PublishSubject: Starts empty and only emits new elements to subscribers. • BehaviorSubject: Starts with an initial value and replays it or the latest element to new subscribers. • ReplaySubject: Initialized with a buffer size and will maintain a buffer of elements up to that size and replay it to new subscribers. • Variable: Wraps a BehaviorSubject, preserves its current value as state, and replays only the latest/initial value to new subscribers. Four subject types in RxSwift Subjects Types. A t t i a M o @AttiaMoTheDev

Slide 22

Slide 22 text

A t t i a M o @AttiaMoTheDev

Slide 23

Slide 23 text

Operators are the building blocks of Rx, which you can use to transform, process, and react to events emitted by observables. Just as you can combine simple arithmetic operators like +, -, and / to create complex math expressions, you can chain and compose together Rx's simple operators to express complex app logic. What is an Operators? Operators. A t t i a M o @AttiaMoTheDev

Slide 24

Slide 24 text

Filtering Operators Transforming Operators Combining Operators Time Based Operators Operators Types Operators. A t t i a M o @AttiaMoTheDev

Slide 25

Slide 25 text

A t t i a M o @AttiaMoTheDev

Slide 26

Slide 26 text

A t t i a M o @AttiaMoTheDev

Slide 27

Slide 27 text

A t t i a M o @AttiaMoTheDev

Slide 28

Slide 28 text

➕ A t t i a M o @AttiaMoTheDev

Slide 29

Slide 29 text

⏳ A t t i a M o @AttiaMoTheDev

Slide 30

Slide 30 text

Considering that schedulers are simply a context, which could be anything (a dispatch queue, thread, or a custom context), and that all operators transforming sequences need to preserve the implicit guarantees, you need to be sure you’re using the right scheduler. Schedulers. Schedulers. A t t i a M o @AttiaMoTheDev

Slide 31

Slide 31 text

⌚ A t t i a M o @AttiaMoTheDev

Slide 32

Slide 32 text

RxTest is a separate library from RxSwift. It’s hosted within the RxSwift repo but requires a separate pod install and import. RxTest provides many useful additions for testing RxSwift code, such as TestScheduler, which is a virtual time scheduler that gives you granular control over testing time-linear operations, and methods including next(_:_:), completed(_:_:), and error(_:_:) RxTest RxTest. A t t i a M o @AttiaMoTheDev

Slide 33

Slide 33 text

A t t i a M o @AttiaMoTheDev

Slide 34

Slide 34 text

A t t i a M o @AttiaMoTheDev - Community

Slide 35

Slide 35 text

A t t i a M o @AttiaMoTheDev https://github.com/RxSwiftCommunity

Slide 36

Slide 36 text

A t t i a M o @AttiaMoTheDev https://github.com/RxSwiftCommunity

Slide 37

Slide 37 text

A t t i a M o @AttiaMoTheDev / Resources

Slide 38

Slide 38 text

https://store.raywenderlich.com/products/rxswift RW-Book, Marin Todorov account and all the book authors. Realm Academy, Rxmarbles A t t i a M o @AttiaMoTheDev

Slide 39

Slide 39 text

A t t i a M o @AttiaMoTheDev Learn & Master ⚔ the Basics of RxSwift in 10 Minutes https://rxmarbles.com/#throttle https://academy.realm.io/posts/try-swift-nyc-2017-krunoslav-zaher-modern- rxswift-architectures/ https://www.codingame.com/playgrounds/929/reactive-programming-with- reactor-3/Intro https://github.com/mohammadZ74/MVVMRx_SampleProject

Slide 40

Slide 40 text

A t t i a M o @AttiaMoTheDev $ Reactive Programming % & ReactiveX ' ( RxSwift ) * RxSwift ⌚﹠ - Community / Resources Recap .

Slide 41

Slide 41 text

Thanks. A t t i a M o @AttiaMoTheDev