In this article, we’ll learn about Operation
dependencies and how they help us chain several operations, resulting in isolated and reusable business-logic components. We’ll chain two operations: one for loading an image and another for adding a sepia effect to it.
In short, this is what we’ll master:
Operation
class to download imagesCIFilter
and to add a sepia effect to an UIImage
This is the result we’ll have by the end of the tutorial:
In this tutorial, we will learn how to implement a circular loading indicator in Swift. By the end, you will have a reusable UI element you can use in your apps to suit your needs.
In short, this is what we will master in this article:
CAShapeLayer
and UIBezierPath
CABasicAnimation
and CAKeyframeAnimation
CAAnimationGroup
This is the result we are going to achieve:
Today, we will learn how to use NSCache
in Swift to cache images inside a UICollectionView
.
In short, this is what you will master in this tutorial:
NSCache
is and how to use it.UICollectionView
layout.NSCache
instead of a plain Dictionary
when we want to cache heavy objects.This is what we will have at the end of this article:
In this article, we will learn how to limit the number of ongoing network requests using a DispatchSemaphore
.
Limiting resource-heavy operations allows us to manage thread resources more efficiently. For example, when you have a task to simultaneously fetch ten high-quality images, it is useful to allow the execution of only one or two image loading operations at a time.
In short, this is what you will master in this tutorial:
DispatchQueue
.DispatchSemaphore
and setting the max number of concurrent operations.sync
and async
executions.First, let’s create a URL
, a background DispatchQueue
, and a DispatchSemaphore
with a value of…
Consider this case: A specific screen in your app requires firing two different requests at the same time. Your goal is to update the UI only after both of them complete. In this tutorial, we will learn how to observe the completion of several network requests using Combine.
We will leverage a powerful .zip
operator that allows us to receive a tuple containing events from several upstream Publishers
.
In short, these are the topics you will master in this tutorial:
Publishers
using the .zip
operator.URLSessionDataTask
publisher..map
…In this article, we will learn how to create a reusable UI element — a bottom sheet.
At the end of the tutorial, you will have a finished component you can easily copy and paste into your app and use to suit your needs.
This is what we are going to build:
In this article we will learn about the difference between leading and left, trailing and right constraints in Swift.
In short, by setting the leading constraint we set the starting point of a view, while the trailing constraint sets the ending point. If we are using English language in our app, leading and left anchors are the same thing, just like the trailing and right ones. But if we add support for RTL (Right-to-left) languages like Arabic, Hebrew, or Urdu, leading will mean right, and trailing will mean left.
Now let’s explore this difference on a simple example.
Our ViewController
has a rounded UIView
containing a…
In this article, we will learn how to architect and create an efficient and easy to use networking layer by leveraging Combine publishers, Codable, CustomStringConvertible protocol, and a custom Endpoint struct.
At the end of the tutorial, you will have a ready-to-use implementation that you can easily copy and paste in your app and expand it the way you want.
The full source code is available at the bottom of the article.
Before we dive into the code, let’s first outline all components of our networking layer:
struct
that has path
and queryItems
properties. By defining extensions on it, we can conveniently create a base URL of our REST APIs, define specific endpoints and headers (that will make more sense to you as we start implementing it, so don’t worry). …In this tutorial, we will learn how to easily observe UserDefaults
using a Combine publisher.
Without further ado, let’s get started.
Consider a case where you want to persist a game’s music volume in UserDefaults
. You also want to observe the change and react accordingly. So our first step is to define the following extension:
As we can see, the getter returns the Float
value for the music_volume
key and the setter sets the new value for that key.
Next, let’s import Combine and add the subscriptions
property to store our future subscription:
Now we can add the actual subscription inside the viewDidLoad()
…
In this article, we will learn how we can easily automate debugging Swift objects using a handy CustomStringConvertible
protocol conformance in an extension.
The source code of the extension is available at the bottom of the article.
Without further ado, let’s get started.
If you have ever conformed to the CustomStringConvertible protocol, then this code looks very familiar to you:
About