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
Extensions for NSControl and UIControl #2182
Comments
FWIW I've been using the extensions provided by @ColinEberhardt's Swift/RAC sample projects: It would be cool if the official extensions similarly exposed not |
@patr1ck The above extensions are great, however I think that the implementation can be dangerous and/or confusing in the wrong hands, and when used in conjunction with I would recommend that if used, the approach be modified slightly so that a new imageView.rac_image <~ viewModel.fetchingSignalProducer
textView.rac_text <~ viewModel.otherSlowTextSignalProducer will lead to an explosion of long-lived signals as the user scrolls. If your Instead, if we replace the I am also aware of the approach to monitor Frankly, I feel it is much less confusing if the "binding operator" as applied above replaces an existing binding rather than allowing many signals to target the same property by accident. Spending some time with Instruments last night / this morning I have also found that the Just throwing my $0.02 on the pile… /cc @ColinEberhardt |
Generally, you should avoid re-binding, especially in your table view cells. Instead, I would recommend exposing a |
@neilpa I like the idea, but how would this look in practice? When asked to configure a Because RAC3 (and the |
Exactly
Yea, if the view model provides producers or properties for these then you'll want to use // N.B. github comment box compiled
public let viewModel: MutableProperty<MyViewModel?> = MutableProperty(nil)
private var imageView: UIImageView!
private var textView: UITextField!
func viewDidLoad() {
imageView.rac_image <~ viewModel.producer
// Every time the viewModel property changes you can re-fetch the new image.
.flatMap(.Latest) { vm in
return vm?.fetchImage() ?? SignalProducer(value: nil)
// or if it exposes an image property instead of a producer
// vm?.imageProperty.producer ?? SignalProducer(value: nil)
}
// may also need to flatMapError (previously catch) if the above producer
// returns something other than NoError
textView.rac_text <~ viewModel.producer.map { $0?.someText ?? "" }
} I've found this pattern to work well for most views, not just cells. |
I've even messed around with creating a of |
This is great, Neil! So with all this said, will changes to the underlying |
@liscio Assuming the returned producer from |
@neilpa Does this approach also work on RC1 or is it only for the swift2 version? When I do |
It should work for 1.2 as well.
I typed this up quickly in the browser without testing it. That should be
In whatever way makes the most since for your UI. Just need to return a "reasonable" value when the view model is nil. For text views that's often empty strings. |
Edit: I was mixing two things together ( If I think the second example is what matters. Is there a better way to do it? |
@neilpa could you please create simple project with example of your approach for ViewModel and table cell binding? |
@ivan-ushakov Sorry, but not anytime soon |
Any update on the progress? |
I'd be in favor of adding this to the next version milestone. This is what I've been using. It would probably be a good idea for now to implement this in terms of the Objective-C APIs: https://gist.github.com/NachoSoto/25b0003c1b15d7d11a8d |
A few weeks ago I created a library that I've been using to pull in a lot of the work related to binding with UIKit. I would love to get some feedback. https://github.com/mpurland/ReactiveBind I've also created a library around MVVM. |
These should be ported from the Objective-C API, so we can create well-typed versions in Swift.
The README should also be updated when this happens.
The text was updated successfully, but these errors were encountered: