It’s time to discover how to manipulate the data in your Combine code

Introduction

In Combine, the methods that perform an operation on values coming from a publisher are called operators.

Each Combine operator returns a publisher that, received the values, manipulates them and then send them to its subscribers.

The operators can be divided in 5 macro categories, based on how they manipulate the data:

  1. Transforming Operators
  2. Filtering Operators
  3. Combining Operators
  4. Time Manipulating Operators
  5. Sequence Operators

Transforming Operators

This operators typology is useful for manipulating the values in order to make them usable for the subscribers.

Collect() operator provide a convenient way to transform a stream of individual values from a publisher into an array. This happens because collect acts as a buffer for these individual values and then it will insert them in an array after the publisher completes. …


Start your journey inside Apple framework dedicated to asynchronous programming

Image for post
Image for post

Introduction

Before going deep inside the Combine Framework, it’s better to recall the difference between synchronous and asynchronous programming, in order to outline the context in which we are going to work.

With synchronous programming, we’re referring to all that programs wrote in a single-threaded language that execute sequentially line-by-line. Because of that, we’re always sure about the current state of our variables.

With asynchronous programming, instead, we’re referring to all that programs wrote in a multi-threaded language that are running on an asynchronous event-driven UI framework like UIKit. …


How to have more control on how your program is executed with Schedulers and Combine

Introduction

If you are experienced with iOS app development, you surely found yourself in a thread error because you tried to update the UI from a closure or something like that, and searching on the net you discovered about DispatchQueue.main and threads.

Now, you will learn something more on them and about using them with Combine.

Let’s start saying what is a Scheduler.

From Apple documentation about Combine you can read that a Scheduler is “a protocol that defines when and how to execute a closure”, and that’s true, but it’s not all. …


If you really need them

Image for post
Image for post
Photo by Jason Leung on Unsplash

As you’ve seen during the Combine learning path, publishers and subscribers cooperate with each other creating a powerful tool to exchange information inside your application.

Maybe the publishers provided by the framework will be enough for your work, but what about custom publishers? Is it possible to create custom ones and, if yes, how to do it?

Of course, it is, and it’s not really complex as it may seem at first. First of all, in order to create a working stream, we need three things:

  1. Publisher
  2. Subscription
  3. Subscriber

Using Combine, you see mostly publishers and subscribers — but the real magic behind the communication is made possible by subscription. …


Nowadays, even simple apps rely on Internet connectivity and no matter how hard networking theory may be, doing connectivity has always been simplified via URLSession.

As the JSON format increase in popularity, Apple has started to develop a way to combine Swift code with JSON data, giving the birth to Codable, making decoding and encoding really easy.

URLSession is the preferred way to perform network data transfer tasks. It offers a modern asynchronous API with powerful configuration options and fully transparent backgrounding support. Some of the operations supported are:

  • Data transfer tasks to retrieve the content of a URL
  • Download tasks to fetch data from a URL and save it to a…


Why Combine framework is highly compatible with SwiftUI framework?

SwiftUI is an alternative to classic UIKit that allows developers to build their UI cross-platform using a declarative approach.

If you have already seen Combine code, you may notice that both Combine and SwiftUI share a declarative programming approach… but that’s not what makes them so… combinable!

The key feature of SwiftUI is the concept of Source of truth.

What does it mean? …

Combined Tutorials

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store