While working on the SwiftUI package for downloading and displaying images I run into the need of implementing image decoding. I used Image I/O and WebKit source code to implement a custom image decoder in Swift.

Why would you need to use a custom image decoder? For me there were two problems to solve: incrementally load an image and displaying animated images.

Loading an image incrementally allows displaying partial image while loading is in progress. Not all image formats support this. An image must be encoded in interlaced format.

Displaying animated images is another reason to use a custom image…


Modern app development with SwiftUI and Combine eliminates a lot of boilerplate code. Tools like Playgrounds extend this further to allow quick prototyping. One common issue is to load arbitrary content (JSON or binary) from network and display it in a SwiftUI view. The other day I was looking for a simple yet elegant way to use in quick prototypes. I came up with a reusable view that can load arbitrary content. After a couple of iterations I discovered some interesting tricks to share.

Content Loading Design


Parsing and evaluating code is underrated topic in modern development. We have all the programming languages ready for us. However, it is not that hard to create a custom language. Recently I found ANTLR, a powerful tool for parsing text, available in Swift. So I decided to describe how to use it to build a calculator.

Why would there be an article how to make a calculator app? Well, this is not a simple calculator. It takes input as a plain text, parses it into a set of instructions, and evaluates them. Similar to how interactive programming environments do.

This…


Dependency inversion is a way to decouple software modules by inverting connections between them and using intermediate abstractions to hide implementation details. This helps to create independent modules, change or replace one module without touching dependent modules. Here are just some benefits:

  • Modules can be reused in multiple apps;
  • Code can be tested independently by mocking dependencies;
  • Frameworks and libraries can be updated and replaced easily.

Dependency inversion is a part of SOLID principles used as a best practice guide in modern software design.

What makes it inversion?

Dependency means that you have module A that uses, therefore depends on, module B:


Swift Package Manager smoothly integrates with the workflow in Xcode 11, but comes with one small limitation: we can not bundle resources with Swift packages. For Core Data this means that we can not include model files.

The solution is to create Core Data model programmatically. Let’s see how we can do this and the process can be improved.

TL;DR; I encountered this problem when I decided to create the index of downloaded images for my URLImage package. I came up with declarative approach and created a separate Swift package: CoreDataModelDescription to describe the model in code.

Core Data model in code

Core Data provides…


Views that download image from URL are extremely popular in iOS development. It is very convenient to set a URL on a view and get an image displayed. And not to worry about networking, caching, and synchronization.

SwiftUI came out without native support for downloading images. This presented an opportunity to create one, native to SwiftUI, and without UIView legacy.

After more than a year of development, and two released versions, I have some thoughts why there is no native one. I will keep `em for the end of the article. …


Controlling view hierarchy is important for architecture, preventing visual and user interaction bugs, and also performance optimizations. Many issues I see related to touch events not handled or layout off from expected. Understanding how view and view controller hierarchies interact and ability to easily navigate through this interconnection will delight your development process.

This article is about how UIView, UIViewController, and UIWindow connect. I explain how to traverse hierarchy of views, view controllers, and the responder chain. We will explore how app’s structure looks with push, modal, and embed presentations. …


What affects performance of the iOS app? How to build beautiful UI and stay responsive? Why a table view or a collection view scrolling can be slow?

Performance is a complex problem. Rendering is one of components often overlooked and yet easy to improve.

In this article I want to overview strategies for improving rendering performance of iOS, UIKit apps.

When saying UIKit apps I want to emphasize focus on native apps built using UILabel, UIImageView, UITableView, etc. E-commerce, educational, productivity, and other categories. If you’re not using UIKit directly, use hybrid technology, or building a specialized graphic app, you…


Recently I had to build a Command Line Tool second time in one month, so I decided to document the setup I use.

The simplest way to create a Command Line Tool is to use Xcode template. But it lacks a crucial part — argument parsing. Swift Package Manager contains Utility package that has exactly what we need.

Without further do, here are the steps:

1. Create and navigate to a directory for the command line tool

mkdir commandlinetool
cd commandlinetool

By default, the name of the directory will be the name of Xcode target and the tool.

2. Create Swift package with type executable

swift package init --type executable

This will create initial files and folders including hidden…


In this article I will describe how to extend Array in Swift by creating a custom sequence. I will also describe how type system in Swift provides requirements and allows to optimize the standard library.

The Idea

Let’s write a method that flattens nested (multidimensional) array. I will call it recursiveFlatten becase it is supposed to concatenate all elements in nested arrays recursively. Element of an array can be a collection or arbitrary object:

[1, [2, 3, [[4], 5]]].recursiveFlatten()
[1, 2, 3, 4, 5]

Array has joined method that concatenates elements of two-dimensional array. …

Dmytro Anokhin

iOS Developer, here to share best practices learned through my experience. You can find me on Twitter: https://twitter.com/dmytroanokhin

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