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

Validating text fields


Until now, everything is quite traditional with regard to developing with Xcode, but now we are going to start using the ReactiveCocoa framework. Let's start with only the username text field. If it is valid, its border must change to green. This way, the user will know that they have introduced a valid value.

Click on your ViewController.swift file and take a look at the viewDidLoad method. Here, we are going to check whether the ReactiveCocoa signals are working and try to understand the concept behind them first. Type the following highlighted code in viewDidLoad and run your code using commandR:

    override func viewDidLoad() { 
        super.viewDidLoad() 
        nameTextField.rac_textSignal().subscribeNext { (input) -> Void in 
            print(input) 
       } 

    } 

Once the application starts running, tap on the username text field and start typing your name. Have a look at the log console and ensure that each letter typed...