Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Reactive Programming with Swift 4

You're reading from   Reactive Programming with Swift 4 Build asynchronous reactive applications with easy-to-maintain and clean code using RxSwift and Xcode 9

Arrow left icon
Product type Paperback
Published in Feb 2018
Publisher Packt
ISBN-13 9781787120211
Length 320 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Navdeep Singh Navdeep Singh
Author Profile Icon Navdeep Singh
Navdeep Singh
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Migrating from Swift 3 to Swift 4 2. FRP Fundamentals, Terminology, and Basic Building Blocks FREE CHAPTER 3. Set up RxSwift and Convert a Basic Login App to its RxSwift Counterpart 4. When to Become Reactive? 5. Filter, Transform, and Simplify 6. Reduce by Combining and Filtering and Common Trade Offs 7. React to UI Events – Start Subscribing 8. RxTest and Custom Rx Extensions – Testing with Rx 9. Testing Your RxCode – Testing Asynchronous Code 10. Schedule Your Tasks, Don't Queue! 11. Subscribe to Errors and Save Your App 12. Functional and Reactive App-Architecture 13. Finish a Real-World Application 14. Other Books You May Enjoy

What this book covers

Chapter 1, Migrating from Swift 3 to Swift 4, teaches what’s new in Swift 4 and how you can transition your code from Swift 3 to Swift 4. Unlike the previous Swift releases, this time the conversion is more seamless, and you will see this in practice with the help of an example.

Chapter 2, FRP Fundamentals, Terminology, and Basic Building Blocks, takes you through FRP and its basic building blocks, marble diagrams, and sequence diagrams to understand more about sequences and events in brief. Finally, the chapter will unleash Railway-oriented programming and a brief introduction on error handling in FRP.
You will learn how you can handle errors in one single place without having to care about handling errors at every single event.

Chapter 3, Set up RxSwift and Convert a Basic Login App to its RxSwift Counterpart, explains that the best way to get the feel about any topic is practice. This chapter will take a nosedive into the RxSwift world by converting an existing Swift app into RxSwift. You will see the RxSwift syntax for the very first time in this chapter and get to work with a real-world application.

You will get a feel of how to convert an existing code base into a RxSwift code base and compare the benefits of the newly learned reactive concepts.

You will note the increased readability and concise but clear code that can be written using the RxSwift library when compared to normal Swift. The gist of this chapter is to provide you with a comparison to understand the benefits that RxSwift code brings into play.

Chapter 4, When to become Reactive?, helps you to use your armor judiciously, as it might lead to increased complexity if not used in a proper setting. When writing any code, keep in mind that the best code might not be the smartest code out there, rather, the best code is the one that is easier to maintain and understand. This chapter will brief you about when to use RxSwift in your application. You will also work with playgrounds to understand some more core concepts that enable you to simplify your complex code base.

Chapter 5, Filter, Transform, and Simplify, along with the next chapter, teaches you how to apply operators to filter out events and then proceed to handle them. You will play with major building blocks of RxSwift and note the clarity and control that you get as compared to normal Swift code while dealing with event-driven concepts. In this chapter, you will work with Playgrounds to transform sequences by filtering them using map, flatmap, and other such operators as they are generated so that you can take respective actions as per the type of the event that is generated.

Chapter 6, Reduce by Combining and Filtering and Common Trade Offs, might sound tedious to read at first, but the concepts will get more clear as we practice with real examples. In this chapter, you will work with some more transforming operators to reduce the observable data stream by making use of combining and filtering operators in conjunction and then gradually work your way to know other operators, such as mathematical and time based.

You will also read about the trade-offs while incorporating these operators in your code so that you can be careful while making the choice to go reactive.

Chapter 7, React to UI Events – Start Subscribing, introduces you to another framework, which is part of the original RxSwift repository—RxCocoa.

Convert your simple UI elements such as UIButtons and UITextFields to Reactive components. You will learn how to subscribe to events emitted by your newly created reactive UI components and perform respective actions depending on the type of the event. For instance, a UIButton might have a touchUpInside or long press event, and you might want to respond to both the events differently.

This chapter will also introduce you to some reactive networking code and how you can subscribe to events while your code is interacting with API calls.

Chapter 8, RxTest and Custom Rx Extensions – Testing with Rx, discusses RxTest, and later, RxBlocking, by writing tests against several RxSwift operations and also writing tests against production RxSwift code. Also, you will create an extension to NSURLSession to manage the communication with an endpoint.

Chapter 9, Testing Your RxCode – Testing Asynchronous Code, says that almost every IOS app needs some sort of API access to fetch or save data over cloud to complete its workflow and hence it becomes important to test code that interacts with APIs. Since response from APIs is uncertain and error prone, the code that interacts with APIs should be tested rigorously before shipping with production code. This chapter introduces you to concepts such as mocking, stubbing, dependency injections, and expectations and sheds some light on how you can substitute your live APIs with dummy data.

You will also know how to continue development even when your API is not ready and, as a result, fasten your sprints.

Chapter 10, Schedule Your Tasks, Don't Queue!, informs that in traditional Swift, there are different ways to handle concurrency—GCD, Operational Queues, and so on. This chapter introduces you to the concept of schedulers. RxSwift encourages a developer not to work directly with locks or queues, and 99% of the times, you will be encouraged to use platform-provided schedulers rather than creating custom schedulers.

Chapter 11, Subscribe to Errors and Save Your App, describes that it does not take long for negative inputs to pour in when an app with users in production shuts down abruptly. This chapter will cover the beauty behind error handling in RxSwift. You can subscribe to errors and react to different types of errors either in one way or follow a specific path for specific errors, for instance, retrying if a download failed abruptly, reauthenticating a user behind the scenes if the session has expired, and so on.

Chapter 12, Functional and Reactive App-Architecture, compares different design patterns that can be used while writing RxSwift apps from scratch or modifying current apps to incorporate Reactive and functional behavior. You will know about observation, iteration, delegation, MVC, and MVVM and try to figure out which design pattern fits the puzzle in the best way possible. This chapter will also introduce you to different open source APIs that can be incorporated to your ongoing projects.

Chapter 13, Finish a Real-World Application, concludes that you would have covered a lot so far and worked on a lot of code examples; now, you will put everything that you have learned so far to practice in one place and finish an app that we started earlier in Chapter 2, FRP Fundamentals, Terminology, and Basic Building Blocks. This chapter will cover the MVVM application architecture and show how a well-designed ViewModel can power an RxSwift app.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image