I am trying to deep dive into RxSwift and figure out different approaches. I realized some project in Github using similiar code structure as below. I used to think as imperative way but I really wonder what i am missing in Rxswift world.
class ViewController: UIViewController {
let observableProperty = PublishSubject<Client.DelegateEvent>()
struct Client {
static var live: Self { Client(events: { stringInputFromSomeWhere in
observableProperty.asObservable() // Point 3
}, setable: {
{ _ = SomeManager().doNothing() }
}, someId: "cool property")}
var events: (String) -> Observable<DelegateEvent>
var setable: () -> ()
var someId: String
init(events: @escaping (String) -> Observable<DelegateEvent>,
setable: @escaping () -> (),
someId: String
) {
self.events = events
self.setable = setable
self.someId = someId
}
public enum DelegateEvent {
case didUpdate(SpecialLocation)
case didFail(Error)
}
}
struct SpecialLocation {
}
class SomeManager {
func doNothing() {
print("noThing Worked")
}
}
override func viewDidLoad() {
super.viewDidLoad()
let clearStep = Client.live.someId // Point 1
let whoAreYou = Client.live // Point 2a
whoAreYou.setable() // Point 2b
print(whoAreYou.someId)
}
Point 1 - Am I accessing a string property of a instance, right ?
Point 2ab - I think, I am accessing an instance after calling a closure,Actually what am I doing here?
Point 3 - Getting error, Cannot convert value of type '()' to closure result type 'Observable<ViewController.Client.DelegateEvent>' So How can I fix this in a meaningful way ?
Thank you so much for every answer and comment.