ios - Rx-Swift Clean architecture -
i want design swift app using clean architecture.
i have read link below on clean architecture swift
i have used these templates create app.
i wanted ask if best architecture use want code using rx-swift.
also appreciate if point out few working examples clean architecture reactive swift.
is using uncle bob’s clean architecture swift(http://clean-swift.com/blog/) best practise rxswift or should go mvvm architecture
any appreciated. thank you.
hi i'm using rxswift clean architecture project
in case, use them in profile scene looks instagram
use case of profile scene
- user should refresh profile scene
- user should chance photo's category
- user should load more photo's pagination
problem is, user can change post's category rapidly then
last fetched post's should different selected category :(
all event cause event asyncronousely
so use rxswift
in interactor has profileworker(to fetch profile , category's post count), postworke(to fetch posts)
and create 3 rxswift publishsubject
- rxcategory - rxprofile - rxposts
step below
interactor
subscribe rxcategory
viewcontroller
request category change interactor
interactor
cause event rxcategory.on(event<category>.next(category))
interactor
using rxswift's flatmaplatest request posts selected category 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]>
postservice (request server using alamofire
, swiftyjson
)
then postservice
return observable<posts>
worker return interactor
interactor
subscribe postsworker
's observable , update posts , cause rxposts
s event accur
interactor
subscribe rxprofile
, rxposts
using combinelatest
and request presenting combined response 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 example using rxswift + clean swift architecture
in situation, if user tap food
category , worker fetch many posts
and user tap place
category , fetch small posts sometimes
although user tap people category. food posts fetched after people's posts
so use rxswift match correctly selected category using flatmaplatest reativex - flatmaplatest
this can fetch , present presentor
latest category's posts
rxswift known useful in mvvm
architecture.
but think it's how can use them
thank reading :)
Comments
Post a Comment