Book Image

Reactive Programming with Swift

By : Cecil Costa
Book Image

Reactive Programming with Swift

By: Cecil Costa

Overview of this book

<p><span id="description" class="sugar_field">Reactive programming helps you write applications that are more powerful and efficient. You can write more software, help more people, and create applications that scale. Reactive programming is a growing paradigm that we will help you set to work in Swift.</span></p> <p><span class="sugar_field"><span id="description" class="sugar_field"> Reactive Programming with Swift guides you through migrating from the traditional way of developing to the new ReactiveCocoa framework, which uses Swift as its main programming language. You will learn how to develop with this framework, debug code, create unit tests, use additional frameworks, and convert a traditional framework into a ReactiveCocoa one.</span></span></p> <p><span class="sugar_field"><span id="description" class="sugar_field"><span id="description" class="sugar_field"> Starting with a crash course on the fundamental concepts of Reactive programming, we’ll set you up so you’re ready to create reactive applications. We’ll then move on to topics such as Graphical events, Streaming, and Core data, which will help you dive deeper with advanced programming. The concept of switching your programming concepts from imperative to functional reactive programming will also be covered. By the end of this book, you will be able to successfully create highly functional apps using Swift.</span> </span></span></p>
Table of Contents (14 chapters)
Reactive Programming with Swift
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Selecting the gender of the user


So far, the application has control for the text fields and the date picker, but it still needs to ask the user their gender. To fix this, we have two buttons with an image of an empty circle on them. These buttons work as radio buttons; when one of them is selected, the other one should be deselected. Why don't we use a switch instead? A switch has two states, on and off, and here, we would like a third state that is not is selected, which means that there is no gender selected by default.

Once the user has tapped on the gender button, it doesn't matter which one, the corresponding signal must be valid. How can we do this? It's very easy: first, we have to take the TouchUpInside signal of each button, and map it to the true value of a Boolean. Let's visualize it by placing the following code before the combineLatest call:

        let womanSignal = womanButton.rac_signalForControlEvents(.TouchUpInside).map { (signal) -> AnyObject in 
            return...