This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
signal.skipRepeats().observeNext {(value) -> () in | |
// print values that are not duplicates of the immedately preceding value | |
print(value) | |
} | |
signal.observeNext {(value) -> () in | |
// values without transformations | |
print(value) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// creating a signal | |
let (signal, sink) = Signal<Int, NoError>.pipe() | |
// function called when button is tapped | |
func buttonTapped(sender: UIButton) { | |
// sending random value down the stream | |
sendNext(sink, random() % 3) | |
} | |
// somewhere in the application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let producer = countToValue(5) | |
producer.startWithSignal { (observer, disposable) -> () in | |
observer.observeNext({ (number) -> () in | |
print(number) | |
}) | |
observer.observeCompleted({ () -> () in | |
print("I'm done counting") | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func countToValue(value: Int) -> SignalProducer<Int, NoError> { | |
return SignalProducer { (sink, disposable) -> () in | |
for i in 0...value { | |
sendNext(sink, i) | |
} | |
sendCompleted(sink) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bankAccountBalance.producer.startWithSignal { (observer, disposable) -> () in | |
observer.observeNext({ (value) -> () in | |
print(value) | |
}) | |
observer.observeCompleted({ () -> () in | |
print("completed") | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bankAccountBalance.producer.startWithSignal { (signal, disposable) -> () in | |
signal.observeNext({ (value) -> () in | |
print(value) | |
}) | |
signal.observeCompleted({ () -> () in | |
print("completed") | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bankAccountBalance.producer.startWithSignal { (signal, disposable) -> () in | |
signal.observeNext({ (value) -> () in | |
print(value) | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bankAccountBalance = MutableProperty<Double>(100) |