Fetching, caching, error, and loading view

Image for post
Image for post
Fictional RemoteImage initializer

Update 2019/08/14: Now available as a Swift package 🚀

I want to implement a SwiftUI pendant of the UIKit remote image view we created at my current employer. I can’t share the code but believe me that compared to the following SwiftUI implementation our UIKit code is more complex, uses an external framework, and has more lines of code.

The Goal

Let’s start with a short description of the article’s goal:

Our goal is to create a view that fetches the image at a given URL, shows a loading view during fetching, caches the image, uses the existing SwiftUI image view, and…


How to add support for paginated API responses to SwiftUI lists

Image for post
Image for post
Screenshot of Bootstrap pagination

My latest SwiftUI demo project fetches data from a REST API and then paginates the responses. That’s why I was looking for an easy way to add pagination support to the SwiftUI List view.

In the current beta (Xcode 11 beta 5), there isn’t a ready-to-use functionality provided. That’s why we’ll implement a simple solution in the next few minutes.

The Goal

While we can access an item in the current iteration in the content block of the List view, we know nothing about its current position in the list or how close we are to the end of the list. …


Type Erasure explained through common use cases

Image for post
Image for post
Example constant of type Any

Some of you may already be familiar with Type Erasure and know how to use it. But I’m certain there are still people out there which don’t know about it or don’t know how to use it.

Honestly, I didn’t take a look at it before writing my article about Advanced Lists in SwiftUI. It was a little mystery for me since I listened to a not so good talk at a developer conference a while ago.

Before lifting the secret Type Erasure let’s take a look at the problem it solved for me.

The Problem 💣

I wanted to store objects conforming…


Implement a dynamic list with empty, error, and loading state

Image for post
Image for post
List image (Copyright © 2019 Christian Elies)

Update 2019/08/14: Now available as a Swift package 🚀

Motivation

What do I mean by advanced list?

The app I’m currently working on has many dynamic lists which can represent different states, such as empty, error, items or loading.

I implemented a solution, on top of the data-driven framework IGListKit, to be able to create these type of lists in our UIKit app.

Now, I wanted to implement something similar using SwiftUI. Just a few lines of code, right?

Implementation

In this section, we will take a look at my implementation and the different components I created.

The AdvancedList should be able…


How to implement basic UI components in SwiftUI

Image for post
Image for post
SwiftUI icon (Copyright © 2019 Apple Inc.)

Updated on 07/06/2019: Xcode 11 beta 3

Updated on 07/07/2019: TextField and SecureField initializer changes

Updated on 07/17/2019: List, ForEach, ActionSheet, Modal, DatePicker and Alert changes (Xcode 11 beta 4)

Updated on 7/29/2019: TabView (previously named TabbedView): tabItem modifier supports images, Alert: renamed onTrigger to action, Slider: a range parameter instead of lower and upper bound parameters, SegmentedControl is now a picker with a special style (Xcode 11 beta 5)

Updated on 8/31/2019: No changes required for Xcode 11 beta 6 + 7

Updated on 9/20/2019: No changes required for Xcode 11…


Image for post
Image for post
designed by freepik.com

A long time ago our iOS team decided to try the VIPER Architecture pattern. There are a lot of variations of that pattern around. Over time, we have had a wide variety of use cases for which the classic VIPER Architecture (see below) doesn’t offer standardised solutions. That’s why we modified the Architecture pattern for our needs. Now I want to share our learnings and improvements.

For those of you who don’t know the VIPER Architecture pattern here is a simple example: Let’s say you want to show a list of items in your app. Normally you would only create…

Christian Elies

Software Engineer iOS @eos.uptrade | https://christianelies.de

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