textField.rac_textSignal()
.subscribeNext({ (_) -> Void in
// value is emitted
},
error: { (error) -> Void in
// an error occurs within the stream
},
completed: { () -> Void in
// signal completes successfully
})
Slide 22
Slide 22 text
Stream.transform(f: (x) -> y) -> Stream
Streams are composable
Slide 23
Slide 23 text
1 3 2
2 6 4
map { (x) -> Int in x * 2 }
Streams are composable
Slide 24
Slide 24 text
1 2 4
filter { (x) -> Bool in x % 2 == 0 }
4
2
Streams are composable
Slide 25
Slide 25 text
Double tap!
Demo
Slide 26
Slide 26 text
No content
Slide 27
Slide 27 text
taps
.bufferWithTime(0.5)
.map { ($0 as RACTuple).count }
.filter { ($0 as Int) == 2 }
.subscribeNext { (_) in
println("Double tap!")
}
Slide 28
Slide 28 text
taps
.bufferWithTime(0.5)
.map { ($0 as RACTuple).count }
.filter { ($0 as Int) == 2 }
.subscribeNext { (_) in
println("Double tap!")
}
Slide 29
Slide 29 text
taps
.bufferWithTime(0.5)
.map { ($0 as RACTuple).count }
.filter { ($0 as Int) == 2 }
.subscribeNext { (_) in
println("Double tap!")
}
Slide 30
Slide 30 text
1 2 3
taps
.bufferWithTime(0.5)
.map { ($0 as RACTuple).count }
.filter { ($0 as Int) == 2 }
.subscribeNext { (_) in
println("Double tap!")
}
Slide 31
Slide 31 text
2
taps
.bufferWithTime(0.5)
.map { ($0 as RACTuple).count }
.filter { ($0 as Int) == 2 }
.subscribeNext { (_) in
println("Double tap!")
}
Slide 32
Slide 32 text
taps
.bufferWithTime(0.5)
.map { ($0 as RACTuple).count }
.filter { ($0 as Int) == 2 }
.subscribeNext { (_) in
println("Double tap!")
}
Double tap!
Slide 33
Slide 33 text
RACSignal.combineLatest([
slowToEmitStream,
evenSlowerToEmitStream,
])
.doNext {
let tuple = $0 as RACTuple
processResults(
tuple.first,
tuple.second)
}
.subscribeCompleted { () -> Void in
println("The work is done!")
}
client.loginWithSuccess({
client.loadCachedTweetsWithSuccess({ (tweets) in
client.fetchTweetsAfterTweet(tweets.last,
success: { (tweets) -> Void in
// Now we can show our tweets
},
failure: { (error) -> Void in
presentError(error)
})
},
failure: { (error) -> Void in
presentError(error)
})
},
failure: { (error) -> Void in
presentError(error)
})
Slide 48
Slide 48 text
client.login()
.then {
return client.loadCachedTweets()
}
.flattenMap { (tweets) -> RACStream! in
return client.fetchTweetsAfterTweet(tweets.last)
}
.subscribeError({ (error) -> Void in
presentError(error)
},
completed: { () -> Void in
// Now we can show our tweets
})
Slide 49
Slide 49 text
func loginWithSuccess(
success: () -> Void,
failure: (NSError) -> Void)
{
// function doesn’t return anything
// it jumps into two callbacks based on return
}
func login() -> RACSignal {
// function has a native return value
// a data stream object that we can observe
}
Slide 50
Slide 50 text
SO…
HOW DO I DO THIS?
Slide 51
Slide 51 text
ReactiveCocoa
ReactiveExtensions
RxJava
Bacon.js
Elm
github.com/ReactiveCocoa/ReactiveCocoa
github.com/Reactive-Extensions
github.com/ReactiveX/RxJava
github.com/baconjs/bacon.js
elm-lang.org