ReactiveObjC icon indicating copy to clipboard operation
ReactiveObjC copied to clipboard

How does ReactiveCocoa bind the ImageView, listen to the ImageView and perform the setImage method?

Open CavanLife opened this issue 8 years ago • 1 comments

How does ReactiveCocoa bind the ImageView, listen to the ImageView and perform the setImage method?

CavanLife avatar Dec 21 '17 02:12 CavanLife

UIImageView can be bound with any ReactiveSwift primitive via its image binding target, as long as the RHS would not fail.

For example:

// `fetchAvatarFromNetwork` returns `SignalProducer<UIImage, MyError>`.

imageView.reactive.image <~ fetchAvatarFromNetwork()
    // Ignore the error if the request has failed. So the placeholder would stay.
    .flatMapError { _ in .empty }
    // Set the image immediately to the placeholder.
    .prefix(value: avatarPlaceholder)

andersio avatar Dec 21 '17 07:12 andersio