Rx-Swift Clean Architecture

I want to create my quick application using a clean architecture.

I read the link below about clean architecture for quick

http://clean-swift.com/blog/

I used these templates to create the application.

I wanted to ask if this is the best architecture to use, since I want to code using Rx-Swift.

I would also appreciate if anyone could point out a few working examples for clean architecture with reactive speed.

Uses Uncle Bob's clean architecture for fast ( http://clean-swift.com/blog/ ) best practice for RxSwift or do I need to go with MVVM architecture

Any help would be appreciated. Thanks.

+5
source share
1 answer

Hi, I am using rxswift with recently developed project architecture.

In my case, I use them in the "Profile" scene, it especially looks like instagram

enter image description here

use profile scene case

  • The user must update the profile scene.
  • user can select a category of photos
  • user needs to upload more photos such as pagination

the problem is that the user can quickly change the category of messages, and then

The last selected post should differ from the selected category: (

all events trigger the event asynchronously

so i use rxswift

Interactor has a Worker profile (for receiving a profile and category title), postWorke (for receiving messages)

and create three rxswift PublishSubject as - rxCategory - rxProfile - rxPosts

Step below

Interactor subscribe rxCategory

ViewController change request category to Interactor

Interactor raise the event rxCategory.on(Event<Category>.next(category))

Interactor using rxswift messages flatMapLatest with selected category in postsWorker

 rxCategory.asObservable().flatMapLatest{ (category) -> Observable<[Posts]> in return self.postsWorker.rxFetchPosts(requestModel, category: category) }.subscribe { (event) in if let posts = event.element { self.updatePosts(posts) } } } 

PostsWorker request Observable<[Posts]> on PostService (server request using Alamofire and SwiftyJSON )

then PostService return Observable<Posts> , then the worker returns to the interaction

Interactor subscribe PostsWorker Observed and updated posts, this triggers the rxPosts event for sure

Interactor sign up rxProfile and rxPosts using the combLatest function

and request for submitting a combined response to Presentor

 Observable.combineLatest(rxProfile, rxPosts) { (e1, e2) -> ProfileResponse in return ProfileResponse(profile: e1, posts: e2) }.subscribe { (event: Event<ProfileResponse>) in self.output.presentProfile(event.element!) } } 

this is my example using rxswift + clean fast architecture

in this situation, if the user clicks the FOOD category and the employee retrieves a lot of messages

and press the PLACE button and select small entries and then

although the user clicks a category of people. food messages sent after people reported

so I use rxswift to match the selected category correctly using flatMapLatest ReativeX - FlatMapLatest

it can receive and submit messages in the Presentor about the last category

rxswift, known in MVVM architecture.

but I think you can use them

Thank you for reading :)

+5
source

Source: https://habr.com/ru/post/1258813/


All Articles