xmartlabs / Eureka

Elegant iOS form builder in Swift
https://eurekacommunity.github.io
MIT License
11.77k stars 1.33k forks source link

Feat: simplify rxswift interaction #1935

Open PierreBrisorgueil opened 4 years ago

PierreBrisorgueil commented 4 years ago

Hello :)

For example, a simple control event to catch cell selection :

    var tap: ControlEvent<Bool> {
         let source = methodInvoked(#selector(Base.onCellSelection(_:))).map { _ in }
        return ControlEvent(events: source)
    }

=> Argument of '#selector' refers to instance method 'onCellSelection' that is not exposed to Objective-C

some explanation : https://www.hackingwithswift.com/example-code/language/how-to-fix-argument-of-selector-refers-to-instance-method-that-is-not-exposed-to-objective-c

Actually it's difficult to play with eureka and rxSwift :/

ghost commented 4 years ago

Here is code used for is highlighted. Other methods can be done similarly,

var isHighlighted: ControlProperty<Bool> {
        let source = RxSwift.Observable<Bool>.create { [weak base] observer in
            if let _base = base {
                observer.onNext(_base.isHighlighted)
                _base.onCellHighlightChanged({ _, row in
                    observer.onNext(row.isHighlighted)
                })
            }
            return Disposables.create {
                observer.onCompleted()
            }
        }
        let bindingObserver = Binder<Bool>(self.base) { row, isHighlighted in
            row.isHighlighted = isHighlighted
        }
        return ControlProperty(values: source, valueSink: bindingObserver)
    }