In this article I will show you how I learned to write my own custom Combine operator as part of my Combine journey of learning and understanding.

Preliminary knowledge

Motivation

My struggles against learning Apple’s Combine framework on my own I thought it will be a nice way of learning by trying to build my own operator.

So when I stumbled across a common use case that I can try building an operator for, I challenged myself to do so.

The common use case in hand

Let’s say for example that you have an api service that returns an array of objects (object A) and this Codable object is full of data that we don’t really want to use, perhaps we just want to display on the screen a part of…


Converting the data model into a presentable model is easy now.

Required familiarity

Motivation

When implementing MVVM architecture it’s likely that you have a data model that you would have to do some extra work on it in order to present it on the view.

There are many approaches for dealing with data formatting and the one I prefer the most is handling it on the model side.

Let me show you how I took advantage of the new Swift language feature in Swift 5.2 that was introduced in this Swift Evolution Proposal SE-0249.

Walkthrough

NOTE: Use Swift…


Photo by pixpoetry on Unsplash

Using Codable to parse even the simplest JSON can be a pain when receiving different JSON server responses with missing fields or even null ones.

Overview

In this article I am going to share this nice piece of code that can do magic when it comes to parsing JSON.

Let’s hit it.

Sit back, relax and open up playground.

Happy Path

Let us consider this common codable structs that many of you must have written at least once.

This JSON example is a perfect one. No missing fields, null fields or key-changed fields. Everything is as expected.

Unhappy Path

But what happens if your buddy at the server side decides to surprise you by making some changes in the response JSON? Let’s see the surprise itself.

Oh no…

Arie Peretz

iOS Developer @ Bank Hapoalim, Israel

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