Learn to manage your data at the right places in SwiftUI

Photo by Cameron Venti on Unsplash

Anytime the data changes, the view needs to update. View depends on the data. In our case: a view establishes a direct dependency on specific data / a specific data source.

When building a new view, start by first asking yourself:

  1. What data does this view need?
  2. How will the data interact with the view? For example, does it only display the data or also require write access (data manipulation)?
  3. Where does the view get the data from?

Where your data comes from is the source of truth of your view. This decision has a profound influence on where you…


Everything you need to know to use Combine in your production code

Photo by Joshua Reddekopp on Unsplash

It’s been a while since Apple introduced the Combine framework with iOS 13 in 2019, but I only recently decided to learn it because the majority of active iOS devices are now running iOS 13. There are plenty of resources on the internet (free or paid, reads or code-along) that talk about Combine at all levels. However, I spent many nights feeling confused after going through countless articles before feeling confident enough to write my first import Combine in the production code of my current project.

If you feel the same after spending time learning about Combine, this article is…


Separating the logic inside the table view’s data source will make your code reusable and easier to maintain

an empty table

The Requirements

I don’t need to have expert knowledge in user experience to realize that users don’t like to be left in ambiguity. Users require an immediate and clear visual indicator of the current state of the product they are using. In real life, when there is nothing on the table, we leave it tiny like that. But in an app, we want to show some custom content when the table view is empty to tell the user about that.

If you work in a team with designers, it is their responsibility to give you, the developer, instructions on what to display…


Key Concepts To Help You Understand How SwiftUI Works Behind The Scene

Photo by Jakob Owens on Unsplash

When I first learned SwiftUI, I was amazed by how much is done automatically for us by SwiftUI. For example, I no longer have to write custom UIView.animateWithDurations remember to make constraint changes outside and call view.layoutIfNeeded inside animation block.

We get a lot of conveniences when using SwiftUI. For it to work for us, not against us, there are certain rules we should follow when structuring our View’s code.

SwiftUI Concepts I’ll Be Talking About

Three key players affect how SwiftUI manages and updates the views:

1. Identity

How SwiftUI recognizes views as same, or unique across multiple updates of your app. …


Ditch the archaic syntax and write key-value observations in the Swifty way

Binoculars illustration by @titopixel

Key-Value Observing pattern, commonly known as the KVO pattern had existed since the inception of Cocoa. It is used to notify objects about changes to the properties of other objects.

When it comes to communicating changes between logically separated parts of your app, we have several options. One of the most widely used is the Delegation pattern, as demonstrated in the following example:

  1. It is self-documented. Looking at the code and you will know exactly how you should use it and what it does.
  2. It is reusable. As long as you want a one-to-one relationship.

Delegation is most useful…


Learn how to use Xcode’s graphical interface to manage localized image assets

Localizing image assets interface

Xcode’s graphical interface provides a convenient and powerful way to manage image assets and you should already be familiar with how it is used if you’ve ever included images in your app.

Turns out, it not only lets you manage image assets but also allows you to localize your image assets by providing different images for different locales. All you need to do is define for which locales the assets should be used, and provide the correct localized image for each locale.

This is done for each image asset so that you can choose to localize only those worth localizing.


Learn how an event is propagated and how to handle and un-handle it

Illustration of Responder Chain

Let’s start with a quiz. Consider the view structure:


Let Xcode find localization strings and compile them into files for easier translation

Localization illustration by Esther from Pexels

Xcode had evolved a lot, making it easier than ever to make your app support multiple languages. This post will focus on exporting and importing localization files using Xcode and assumes you have enough knowledge about the process of localization or internalization.

If you need more information on implementing localizations, here are my article recommendations:

  1. Long and thorough: Internationalizing Your iOS App: Getting Started from raywenderlich.com (25-minute read)
  2. Short: Localizations in Swift by Doyen (4-minute read)

The content in this article requires you to be familiar with the process of internationalization in Xcode.

Follow any of the articles and you…


and how to track UISlider events without setting up multiple action handlers

Photo by Donald Tong from Pexels

The Requirement

I started implementing an AVPlayer with standard capabilities. The user can play, pause, and drag the slider (implemented with an UISlider) to seek a point in the video.

While dragging, the player will stop updating the slider with the current progress derived from player.currentTime() / player.duration. Usually, this is done by setting up an observer with player.addPeriodicTimeObserver :

Instead, the slider.value will be used to calculate and reflect the progress pointed by the user’s dragging. Once the user releases the slider, we use player.seek() to continue playing the video from the time converted from slider.value:

On the slider…


Building your own Action Sheet in Swift

Photo by Skitterphoto from Pexels

We should all be familiar with the action sheet that iOS uses in the system settings and Apple native apps:

Jianyuan Chen

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