Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to bind it by RxCocoa #8

Open
selfishout opened this issue Jul 31, 2018 · 3 comments
Open

How to bind it by RxCocoa #8

selfishout opened this issue Jul 31, 2018 · 3 comments

Comments

@selfishout
Copy link

Hi there
I want to populate PinterestSegment reactively from network but I don't know how to get that
screen shot 2018-07-30 at 2 46 30 pm
screen shot 2018-07-30 at 2 46 48 pm

Actually output is a transformation of input to something intelligible for the view and all of those transformation done into ViewModel :

for news which binded to tableView everything works perfectly but when I try binding services (from Service Model) to PinterstSegment , I've got an error which present in above but for the sake of integrity the error is :

Cannot invoke 'drive' with an argument list of type '([String])'

@TBXark
Copy link
Owner

TBXark commented Jul 31, 2018

extension Reactive where Base: PinterestSegment {
    
    /// Bindable sink for `titles ` property.
    public var titles: Binder<[String]> {
        return Binder(base) { segment, titles in
            segment.titles = titles
        }
    }
}

@selfishout
Copy link
Author

Thanks
but how could I bind it to PinterestSegment View as I have trying to do like this :
output.services.drive(newsSegment.rx.titles)
I've got an error : Generic parameter 'Self' could not be inferred

How could I get rid of this annoying error ?
Thanks

@adrianod1as
Copy link

adrianod1as commented Nov 8, 2018

Actually, it works

Driver.of(["it", "works", "!"])
.drive(segment.rx.titles)
.disposed(by: bag)

I believe the problem is that output.services is not a Driver<[String]> type.

P.S.: And since I'm here, I guess I gonna throw another useful extension for future readers. 😄

extension Reactive where Base: PinterestSegment {

    public var valueChange: Observable<Int> {
        return Observable.create { observable in
            self.base.valueChange = { index in
                observable.onNext(index)
            }
            return Disposables.create()
        }
    }

    public var itemSelected: ControlEvent<Int> {
        return ControlEvent(events: valueChange)
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants