Image by M W from Pixabay

It is common in iOS development where UIViewController becomes very messy and hard to manage because it is filled up with every single element, including Views, outlets, actions, cosmetics, layouts and business logics.

In fact, UIViewController should be very simple. It only need to manage the Views and observe the actions occur. In this tutorial, I would like to share one of the best practice that I always apply to my projects.


We are going to break down the screen into multiple UIView components and each UIView component will manage all the layouts and styles themselves. It also will take…

UserDefaults is commonly used to store simple persistence data or state. But, improper key management would lead to future major problem and code messiness. Moreover, sometimes the typo of key name might result to untraced bugs.

Therefore, let’s try to manage the UserDefaults keys in a cleaner way using Enum (Enumeration). Enum is a very powerful data type to group related values in a type-safe way.

So, we are going to use the Enum with String and CaseIterable. The good thing is programmer will always use the pre-defined keys in the Enum and we don’t have to worry about using…

squash, undo latest commits, and more

list of Git messages
list of Git messages
Photo by Yancy Min on Unsplash

I believe nowadays every development should be done along with Git, a powerful collaboration tool to track every single change that occurs in a project so that developers can have a long history of things that have been done. This is very useful, especially if we are working in a team. But I personally will add it to all my projects even though I am working alone. Why? Because I can easily keep track of what I did in the past and quite quickly trace the bugs and mistakes.

In this article, we are going to discuss the useful tricks…

SwiftUI was firstly introduced in WWDC19 and the API has been rapidly improved in every single day. Since last year, Apple has made huge improvement in SwiftUI including layouts, animation and graphics.

There are so many sources that we can use to learn SwiftUI. But, which one will be the best to help us to quickly understand the whole concept. However, it depends and I won’t say that my approach will be the best for everyone. At least, after going through these steps, I can understand (not the whole) how to develop iOS apps in SwiftUI. …

Implement input form validation with two practical examples

Male on a hammock in front of a waterfall
Male on a hammock in front of a waterfall
Photo by Jeremy Bishop on Unsplash

I know that “RxSwift” itself sounds like a big and difficult thing. I was feeling the same when I started working on it. We are all learners. One of the best ways to learn is by adopting the implementation into an existing project. In this article, we will focus on the implementation of form validation in RxSwift.

RxSwift is Reactive Extensions (Rx) for Swift language. It is a well-known library and widely used by iOS developers, especially in MVVM patterns. For more understanding on definition and overview, you may refer to good articles written in Hackernoon and Raywenderlich.

Observable, Subscriber and Subjects

First, you…

Photo by Frederik Lipfert on Unsplash

In software development, we always focus on achieving the end result and sometimes overlook another important measurement to ensure we deliver the best apps to the user.

I know that most of the users nowadays have good Internet connectivity with high-speed WiFi and 4G. However, we cannot deny that at certain conditions the connection sometimes will become very poor and it surely affects the apps normal behavior.

We as a developer should have a good preparation to handle the network failure, such as adding retry functions, network connectivity listener, and of course, showing a proper error message.

What tools do we need?

Since WWDC19, Xcode…

Recently, I have been working on QR Code Scanning project which requires to read the scanned result (URL) and pulling out specific values in query string such as id, flag, success status, etc. Developer sometimes will parse it manually using few String methods and forget about the useful URLComponents.

URLComponents is the best tool to parse and construct url. It has been there since iOS7. Let’s do some practice.

1 — Getting value of specific query

Take a look at this string url example. Don’t click, it just an example 🤭

First, let’s try to find the value of…

Working as beginner developer doesn’t mean we just keep working with basic knowledge we have and waiting assistance from seniors. There is always room to upscale our skill.

Learn, learn and learn.

Swift is one of the powerful language that provides bunch of useful features. In this article, we are going to discuss on 5 useful Swift features and hopefully will level up our skill in iOS development.

1 — Extension

Swift allows us to add more functions through Extension into existing class such as UIViewController, UIView, String, Date, Int and so on. …

Any issue on UIButton?

UIButton basically does not have a built-in function to set its background for multiple state. Developers need an extra effort to make the disabled state to have a different background. In some cases, UIViewControllers might have different functions and approach to manage the background colour for .disabled state (spaghetti code).


Here is the simple solution. A simple subclass of UIButton, to enable background changing based on isEnabled value. So, whenever the value of isEnabled is changed, it will reflect the background color. Awesome!

Please take note, this simple solution only will cover these two states; .normal and .disable state.


What’s the issue?

Creating a project without Storyboard and xib is absolutely possible, but sometimes it can be painful managing UI and constraints programmatically. Thus, what is the effective practice of doing that? Are we able to speed up development time to manage those constraints, sizing and colouring?

Yes, we can. Thanks to SwiftUI Preview for the wonderful feature. It is designed for SwiftUI, and still usable for UIKit.

Advantages of Live Preview feature:

  1. Easy to manage constraints programmatically.
  2. Easy to preview the expected UI without having to run the code and go through the flow (clicking here and there) until reach the…

Mohd Hafiz

iOS Developer focusing on Swift — “Learn, that’s how we grow our skill”.

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