Swift Functional Programming - Second Edition
eBook - ePub

Swift Functional Programming - Second Edition

Dr. Fatih Nayebi

Partager le livre
  1. 316 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

Swift Functional Programming - Second Edition

Dr. Fatih Nayebi

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

Bring the power of functional programming to Swift to develop clean, smart, scalable and reliable applications.About This Book‱ Written for the latest version of Swift, this is a comprehensive guide that introduces iOS, Web and macOS developers to the all-new world of functional programming that has so far been alien to them‱ Get familiar with using functional programming alongside existing OOP techniques so you can get the best of both worlds and develop clean, robust, and scalable code‱ Develop a case study on example backend API with Swift and Vapor Framework and an iOS application with Functional Programming, Protocol-Oriented Programming, Functional Reactive Programming, and Object-Oriented Programming techniquesWho This Book Is ForMeant for a reader who knows object-oriented programming, has some experience with Objective-C/Swift programming languages and wants to further enhance his skills with functional programming techniques with Swift 3.x.What You Will Learn‱ Understand what functional programming is and why it matters‱ Understand custom operators, function composition, currying, recursion, and memoization‱ Explore algebraic data types, pattern matching, generics, associated type protocols, and type erasure‱ Get acquainted with higher-kinded types and higher-order functions using practical examples‱ Get familiar with functional and non-functional ways to deal with optionals‱ Make use of functional data structures such as semigroup, monoid, binary search tree, linked list, stack, and lazy list‱ Understand the importance of immutability, copy constructors, and lenses‱ Develop a backend API with Vapor‱ Create an iOS app by combining FP, OOP, FRP, and POP paradigmsIn DetailSwift is a multi-paradigm programming language enabling you to tackle different problems in various ways. Understanding each paradigm and knowing when and how to utilize and combine them can lead to a better code base. Functional programming (FP) is an important paradigm that empowers us with declarative development and makes applications more suitable for testing, as well as performant and elegant. This book aims to simplify the FP paradigms, making them easily understandable and usable, by showing you how to solve many of your day-to-day development problems using Swift FP.It starts with the basics of FP, and you will go through all the core concepts of Swift and the building blocks of FP. You will also go through important aspects, such as function composition and currying, custom operator definition, monads, functors, applicative functors, memoization, lenses, algebraic data types, type erasure, functional data structures, functional reactive programming (FRP), and protocol-oriented programming(POP). You will then learn to combine those techniques to develop a fully functional iOS application from scratchStyle and approachAn easy-to-follow guide that is full of hands-on coding examples of real-world applications. Each topic is explained sequentially and placed in context, and for the more inquisitive, there are more details of the concepts used. It introduces the Swift language basics and functional programming techniques in simple, non-mathematical vocabulary with examples in Swift.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Swift Functional Programming - Second Edition est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Swift Functional Programming - Second Edition par Dr. Fatih Nayebi en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Computer Science et Programming Mobile Devices. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2017
ISBN
9781787283459

Case Study - Developing an iOS Application with FP and OOP Paradigms

In the previous chapters, we covered a variety of concepts and techniques. We started with FP paradigms and explored related topics in detail. Also, in the previous chapter, we covered other paradigms such as OOP, FRP, and POP, and mixed them together. In this chapter, we will create a simple application using those paradigms.
Most iOS applications need a backend to be able to provide advanced functionalities such as integration with other systems. In this chapter, we will create a simple backend with Swift that is going to be used as a Todo application API. Then, we will develop an iOS application that will leverage our backend and provide some essential functionality such as listing and updating Todo items coming from the backend. Also, our iOS application will be able to create new Todo items. Our iOS application development will include the FP, OOP, POP, and FRP paradigms.
This chapter will cover the following topics:
  • Requirements
  • High-level design
  • Backend development
    • Environment configuration
    • Swift Package Manager
    • Vapor
    • Application development
  • Frontend development
    • CocoaPods dependency management configuration
    • Third-party libraries
    • Backend communication
    • JSON parsing and model mapping
    • State management
    • Listing items with a UITableView
    • Updating and creating items
    • Filtering items

Requirements

This section presents the requirements for our case study. Since the focus of this book is not on requirement engineering, we will define very simple requirements. This section does not present best practices for requirement engineering.
The requirements for the iOS application user are as follows:
  • Users should be able to list Todo items
  • Users should be able to see the details of each item
  • Users should be able to modify items
  • Users should be able to create a new item
  • Users should be able to filter items by their status

High-level design

This section explains the high-level design of the frontend and backend.

Frontend

Application design follows a slightly different version of the Model-View-Controller (MVC) pattern, with the addition of the Actions, Store, State, and Communication layers to simplify the controller layer of the traditional iOS application MVC pattern. All application layers are explained in the following sections.

Models

Plain old model structures. These models do not have any logic and only consist of properties. There are four types of model:
  • TodoRequest: This is a struct that is used in backend request calls and conforms to RequestProtocol
  • Todo: This is a struct that represents Todo data, and uses the Argo and Curry libraries to decode the object from JSON
  • TodoViewModel and TodosViewModel: These structs represent data and are used in views and shown to the user
  • TodoLens: These lenses modify the Todo model
All the aforementioned models are immutable value types.

Views

We have two View subclasses: one to provide a custom UITableViewCell called TodoTableViewCell, and a subclass of UIView named FooterView.
Both of these Views are subclasses of iOS SDK-provided classes. Besides these classes, we will have our UIViewController scenes in the storyboard.

ViewController

ViewController is a subclass of UIViewController or UITableViewController, and it connects views to logic:
  • MasterViewController: This is a subclass of UITableViewController to present Todo items
  • DetailsViewController: This is a subclass of UIViewController to present details of each Todo item to the user
To develop iOS applications, we have to rely on iOS SDK-provided classes such as UIViewController and UITableViewController. The ViewController and UIView subclasses are the only classes that will be used in this case study.

State

In iOS application development, we need to handle states. We use the Delta, ReactiveCocoa, and ReactiveSwift libraries to manage our Todo app's State.
Delta takes an App that has custom State management spread throughout all the ViewControllers and simplifies it by providing a simple interface to change State and subscribe to its changes.
ReactiveSwift offers composable, declarative, and flexible primitives that are built around the concept of streams of values over time. These primitives can be used to uniformly represent observation patterns. ReactiveCocoa wraps various aspects of Cocoa frameworks with the declarative ReactiveSwift primitives.
We will implement a State struct to observable properties.

Store

Our Store struct will wrap State struct and provide properties to observe its changes. Store struct conforms to the Delta library's StoreType protocol, which defines the storage of an observable state and dispatch methods to modify it. Also, Store struct uses the ReactiveSwift library's MutableProperty value and allows observation of its changes in a thread-safe manner.

Actions

Actions are structs that conform to the ActionType protocol from the Delta library. ActionType is used when we want to make modifications to the Store struct's State. All changes to the Store struct go through this type.
We will develop the following Actions in the application:
  • ClearCompletedTodosAction...

Table des matiĂšres