ebook img

RxSwift. Reactive Programming with Swift PDF

398 Pages·2017·24.54 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview RxSwift. Reactive Programming with Swift

RxSwift - Reactive Programming with Swift RxSwift: Reactive Programming with Swift Florent Pillet, Junior Bontognali, Marin Todorov & Scott Gardner Copyright ©2017 Razeware LLC. Notice of Rights All rights reserved. No part of this book or corresponding materials (such as text, images, or source code) may be reproduced or distributed by any means without prior written permission of the copyright owner. Notice of Liability This book and all corresponding materials (such as source code) are provided on an “as is” basis, without warranty of any kind, express of implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in action of contract, tort or otherwise, arising from, out of or in connection with the software or the use of other dealing in the software. Trademarks All trademarks and registered trademarks appearing in this book are the property of their own respective owners. raywenderlich.com 2 RxSwift - Reactive Programming with Swift Dedications "For my father." — Marin Todorov "For Fabienne and Alexandra" — Florent Pillet "For my grandfather." — Junior Bontognali "For Betty ! " — Scott Gardner raywenderlich.com 3 RxSwift - Reactive Programming with Swift About the authors Florent Pillet is an author of this book. Florent has been developing for mobile platforms since the last century and moved to iOS on day 1. He adopted reactive programming before Swift was announced and has been using RxSwift in production since 2015. A freelance developer, Florent also uses Rx on Android and likes working on tools for developers like the popular NSLogger when he's not contracting for clients worldwide. Say hello to Florent on Twitter at @fpillet. Junior Bontognali is an author of this book. Junior has been developing on iOS since the first iPhone and joined the RxSwift team in the early development stage. Based in Switzerland, when he's not eating cheese or chocolate, he's doing some cool stuff in the mobile space, without denying to work on other technologies. Other than that he organizes tech events, speaks and blogs. Say hello to Junior on Twitter at @bontoJR. Marin Todorov is an author of this book. Marin is one of the founding members of the raywenderlich.com team and has worked on seven of the team's books. Besides crafting code, Marin also enjoys blogging, teaching, and speaking at conferences. He happily open-sources code. You can find out more about Marin at www.underplot.com. Scott Gardner is an author of this book. Scott has been developing iOS apps since 2010, Swift since the day it was announced, and RxSwift since before version 1. He's authored several video courses, tutorials, and articles on iOS app development, presented at numerous conferences, meetups, and online events, and this is his second book. Say hello to Scott on Twitter at @scotteg. raywenderlich.com 4 RxSwift - Reactive Programming with Swift About the editors Ash Furrow is the technical editor of this book. Ash is a Canadian iOS developer and author, currently working at Artsy. He has published a number of books, built many apps, and is a contributor to the open source community. On his blog ashfurrow.com, he writes about a range of topics, from interesting programming to explorations of analogue film photography. Chris Belanger is the editor of this book. Chris Belanger is the Book Team Lead and Lead Editor for raywenderlich.com. If there are words to wrangle or a paragraph to ponder, he‘s on the case. When he kicks back, you can usually find Chris with guitar in hand, looking for the nearest beach, or exploring the lakes and rivers in his part of the world in a canoe. Marin Todorov is the final pass editor of this book. Marin is one of the founding members of the raywenderlich.com team and has worked on seven of the team's books. Besides crafting code, Marin also enjoys blogging, teaching, and speaking at conferences. He happily open-sources code. raywenderlich.com 5 RxSwift - Reactive Programming with Swift Table of Contents: Overview Introduction................................................................................ 15 Section I: Getting Started with RxSwift ........................ 21 Chapter 1: Hello RxSwift!.............................................. 22 Chapter 2: Observables................................................ 43 Chapter 3: Subjects......................................................... 62 Chapter 4: Observables and Subjects in Practice.... 76 Section II: Operators and Best Practices....................... 95 Chapter 5: Filtering Operators..................................... 96 Chapter 6: Filtering Operators in Practice .............. 114 Chapter 7: Transforming Operators ......................... 134 Chapter 8: Transforming Operators in Practice...... 146 Chapter 9: Combining Operators ............................. 168 Chapter 10: Combining Operators in Practice....... 188 Chapter 11: Time Based Operators ......................... 208 Section III: iOS Apps with RxCocoa........................... 227 Chapter 12: Beginning RxCocoa ............................... 228 Chapter 13: Intermediate RxCocoa.......................... 247 Section IV: Intermediate RxSwift/RxCocoa................ 267 Chapter 14: Error Handling in Practice.................... 268 Chapter 15: Intro To Schedulers ................................ 285 Chapter 16: Testing with RxTest................................. 299 raywenderlich.com 6 RxSwift - Reactive Programming with Swift Chapter 17: Creating Custom Reactive Extensions. 314 Section V: RxSwift Community Cookbook................. 329 Chapter 18: Table and Collection Views ................. 330 Chapter 19: Action....................................................... 334 Chapter 20: RxGesture ............................................... 339 Chapter 21: RxRealm................................................... 343 Chapter 22: RxAlamofire............................................ 348 Section VI: Putting it All Together .............................. 352 Chapter 23: MVVM with RxSwift .............................. 353 Chapter 24: Building a Complete RxSwift App...... 375 Conclusion ............................................................................... 398 raywenderlich.com 7 RxSwift - Reactive Programming with Swift Table of Contents: Extended Introduction................................................................................ 15 What you need.................................................................................................................. 16 Who this book is for.......................................................................................................... 16 How to use this book......................................................................................................... 17 What’s in store................................................................................................................... 17 Book source code and forums......................................................................................... 18 Book updates...................................................................................................................... 18 License.................................................................................................................................. 19 About the cover.................................................................................................................. 20 Section I: Getting Started with RxSwift ........................ 21 Chapter 1: Hello RxSwift! ...................................................... 22 Introduction to asynchronous programming.................................................................. 23 Foundation of RxSwift....................................................................................................... 30 App architecture................................................................................................................ 37 RxCocoa.............................................................................................................................. 38 Installing RxSwift................................................................................................................ 39 Community........................................................................................................................... 41 Where to go from here?.................................................................................................. 42 Chapter 2: Observables........................................................ 43 Getting started.................................................................................................................. 44 What is an observable?................................................................................................... 45 Lifecycle of an observable.............................................................................................. 46 Creating observables....................................................................................................... 47 Subscribing to observables.............................................................................................. 49 Disposing and terminating............................................................................................... 54 Creating observable factories........................................................................................ 59 Challenges........................................................................................................................... 60 raywenderlich.com 8 RxSwift - Reactive Programming with Swift Chapter 3: Subjects................................................................. 62 Getting started.................................................................................................................. 63 What are subjects?............................................................................................................ 64 Working with PublishSubjects.......................................................................................... 64 Working with BehaviorSubjects....................................................................................... 67 Working with ReplaySubjects.......................................................................................... 69 Working with Variables.................................................................................................... 72 Challenges........................................................................................................................... 74 Chapter 4: Observables and Subjects in Practice ............ 76 Getting started.................................................................................................................. 77 Using a variable in a view controller............................................................................. 78 Talking to other view controllers via subjects............................................................... 81 Which dispose bag to use?.............................................................................................. 86 Creating a custom observable........................................................................................ 89 Challenges........................................................................................................................... 94 Section II: Operators and Best Practices....................... 95 Chapter 5: Filtering Operators............................................. 96 Getting started.................................................................................................................. 97 Ignoring operators............................................................................................................. 97 Skipping operators......................................................................................................... 101 Taking operators............................................................................................................. 105 Distinct operators ............................................................................................................ 109 Challenges........................................................................................................................ 111 Chapter 6: Filtering Operators in Practice ...................... 114 Improving the Combinestagram project...................................................................... 115 Sharing subscriptions...................................................................................................... 116 Improving the photo selector......................................................................................... 123 Trying out time based filter operators........................................................................ 130 Challenges........................................................................................................................ 133 raywenderlich.com 9 RxSwift - Reactive Programming with Swift Chapter 7: Transforming Operators.................................. 134 Getting started................................................................................................................ 135 Transforming elements.................................................................................................... 135 Transforming inner observables................................................................................... 138 Challenges........................................................................................................................ 143 Chapter 8: Transforming Operators in Practice.............. 146 Getting started with GitFeed....................................................................................... 147 Fetching data from the web.......................................................................................... 148 Transforming the response............................................................................................. 152 Intermission: Handling erroneous input........................................................................ 157 Persisting objects to disk................................................................................................ 158 Add a Last-Modified header to the request............................................................. 159 Challenges........................................................................................................................ 163 Chapter 9: Combining Operators...................................... 168 Getting started................................................................................................................ 169 Prefixing and concatenating......................................................................................... 169 Merging............................................................................................................................. 172 Combining elements........................................................................................................ 174 Triggers............................................................................................................................. 179 Switches............................................................................................................................. 181 Combining elements within a sequence....................................................................... 184 Challenges........................................................................................................................ 187 Chapter 10: Combining Operators in Practice ............... 188 Getting started................................................................................................................ 189 Preparing the web backend service........................................................................... 189 Categories view controller............................................................................................ 193 Adding the event download service............................................................................ 194 Getting events for categories....................................................................................... 196 Events view controller..................................................................................................... 200 Wiring the days selector............................................................................................... 202 Splitting event downloads............................................................................................. 204 Challenges........................................................................................................................ 207 raywenderlich.com 10

Description:
Learn reactive programming in Swift with RxSwift!The popularity of reactive programming continues to grow on an ever-increasing number of platforms and languages. Rx lets developers easily and quickly build apps with code that can be understood by other Rx developers — even over different platform
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.