-
Notifications
You must be signed in to change notification settings - Fork 31
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
UIButton.rex_pressed example in README #58
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,28 @@ func propertySink<S: SinkType>(sink: S)(signal: Signal<S.Element, NoError>) -> P | |
func propertySink<S: SinkType>(sink: S)(producer: SignalProducer<S.Element, NoError>) -> PropertyOf<S> | ||
``` | ||
|
||
## UIKit Extensions | ||
|
||
##### `UIButton.rex_pressed` | ||
|
||
Flexible way to bind CocoaAction to the press of button. | ||
|
||
```swift | ||
let downloadAction: Action<Void, NSData, NoError> = Action { _ in | ||
return SignalProducer { observer, disposable in | ||
if let zipURL = NSURL(string: "https://github.com/neilpa/Rex/archive/master.zip") { | ||
if let zipData = NSData(contentsOfURL: zipURL) { | ||
observer.sendNext(zipData) | ||
observer.sendCompleted() | ||
} | ||
} | ||
} | ||
} | ||
|
||
let downloadCocoaAction = CocoaAction(downloadAction, input: ()) | ||
let cocoaActionProducer: SignalProducer<CocoaAction, NoError> = SignalProducer<CocoaAction, NoError>(value: downloadCocoaAction) | ||
startDownloadButton.rex_pressed <~ cocoaActionProducer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be simplified a bit let downloadAction = Action<UIButton, NSData, NSError> { _ in
let url = NSURL(string: "https://github.com/neilpa/Rex/archive/master.zip")
let request = NSURLRequest(URL: url!)
return NSURLSession.sharedSession().rac_dataWithRequest(request).map { $0.0 }
}
downloadButton.rex_pressed.value = downloadAction.unsafeCocoaAction There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only time you need to bind with |
||
``` | ||
|
||
## License | ||
Rex is released under the [MIT license](LICENSE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add another sentence that the button is automatically disabled while the
Action
is executing.