Articles

In-depth articles about iOS programming, techniques, language features, architectual patterns, and beyond.

7 ways to pass a closure as an argument in Swift

There are many ways we can satisfy a closure argument. Some of them do not even look like closure. Let's learn all of them in this article.

How to make a custom button style with UIButton.Configuration in iOS 15

Learn how to create an outline button style.

How to set custom CodingKey for the convertFromSnakeCase decoding strategy

The thing you should know before using the convertFromSnakeCase decoding strategy.

How to define custom environment values in SwiftUI

It might not be obvious that we can create a custom environment value, but we can do that. The steps to create one are not as straightforward as we usually do, but it isn't hard if you know how to do it.

How to reference a method with the same name and parameters but a different return type in Swift

Trying to reference two methods with the same name and parameters will cause an ambiguous compile error. Learn how to resolve it.

How to show multiple alerts on the same view in SwiftUI

If you have ever worked with an app with multiple alerts, please beware that the system can present only the latest or outermost one. Let's see how we can mitigate this.

How to present an alert in SwiftUI in iOS 13/14

Learn how to show an alert (UIAlertController) in SwiftUI.

How to do print debugging in SwiftUI

Learn how to add a print() in a SwiftUI view.

Pop-Up Buttons in SwiftUI

Learn how to create macOS pop-up buttons in SwiftUI.

Different ways to catch throwing errors from Swift do-catch

It is tempting to just catch all a throwing error in a single catch clause and call it a day, but not all errors are created equals, and you should treat it as such.

How to ignore safe area insets in UIKit

Learn how to make UIScrollView, UITableView, and UICollectionView ignore safe area insets and put their content behind that navigation bar.

Spell checking in Xcode

Did you know that you have an option to enable spell checking in Xcode?

How to explicitly specialize a generic function in Swift

Learn a workaround to specify a type for your generic functions.

How to show and hide a sidebar in a SwiftUI macOS app

Once the sidebar is collapsed, there is no way to get it back. Learn how to mitigate the situation.

Dynamic button configuration in iOS 15

Learn how to change button configuration, e.g., title and color, based on the internal and external changes.

Always show search bar in a navigation bar in SwiftUI

In UISearchController, we can set search bar hiding behavior with hidesSearchBarWhenScrolling property. But how to control this behavior isn't obvious in SwiftUI. Learn how to control search bar hiding behavior in SwiftUI.

4 Xcode shortcuts to get back your screen space

Working on your MacBook without an external monitor can be troublesome due to the small screen size. I will show you 4 Xcode shortcuts that might mitigate the situation.

Flutter: How much time do you save, and at what cost

The idea that you can use one codebase for multiple platforms and cut development time by half is tempting, but what do you trade for this time saved?

Searchable modifier in SwiftUI: A UISearchController and UISearchBar equivalent

SwiftUI finally got native search support in iOS 15. We can add search functionality to any navigation view with the new searchable modifier. Let's explore its capability and limitation.

How to manually add existing certificates to the Fastlane match

Learn how to import .cer and p12 to Fastlane match without nuke or creating a new one.

New Formatters in iOS 15: Why do we need another formatter

We have a new way to format data into a localized string in iOS 15. Why do we need another formatter? How does it differ from the old one? Let's find out.

How to share an iOS distribution certificate

Learn how to create, export, and import certificate without any third-party tools.

A better way to ask for a one-time user's location with the Location Button

Asking for sensitive data like location is hard. Learn how Apple makes it easier with the new Location Button.

Preview a device in landscape orientation with previewInterfaceOrientation

New in iOS 15, SwiftUI has finally support preview in landscape orientation. Let's find out how to do it.

How to use a pre-release Swift version with command-line tools

Each Xcode version comes with a specific Swift toolchain. If you want to prepare your app for a new feature and make it work with CI, you want to make your tools, e.g., Fastlane and xcodebuild know about the new toolchain. Let's see how we can switch between different Swift toolchains with command-line tools.

A new way to style UIButton with UIButton.Configuration in iOS 15

The first part in the series "What's new in UIKit button". An introduction to a new button configuration, a struct that is shaping and styling your button. You no longer need to subclass UIButton ever again with button configuration.

How to use a pre-release Swift version in Xcode

Each Xcode version comes with a specific Swift toolchain, but you don't have to wait for a new Xcode version to try the new Swift features. Let's see how we can switch between different Swift toolchains in Xcode.

Pull to refresh in SwiftUI with refreshable

SwiftUI got a native way to add UIRefreshControl in iOS 15. Let's find out how to add it in the list view and even your custom view.

How to change status bar text color in Flutter

Learn different ways to change status bar text color in Flutter.

How to change a back button color in Flutter

Learn different ways to change the back button color in Flutter.

How to make AppBar/Navigation Bar transparent in Flutter

Learn how to make a transparent app bar in Flutter.

How to read App Name, Version, and Build Number from Info.plist

Learn an easy way to read the information in Info.plist.

How to set up iOS environments: develop, staging, and production

Learn how to create a separate environment for your app with the help of Configuration and Scheme. Create a different app and variables for each environment on the same codebase.

How to make a simple bevel effect using inner shadows in SwiftUI

We can make a simple bevel effect using two inner shadows. SwiftUI has a built-in way to add a drop shadow with the shadow modifier. But if you want to add an inner shadow effect, you need to be a bit creative.

What is a Property Wrapper in Swift

As the name implies, a property wrapper is a new type that wraps a property to add additional logic. Let's see what it capable of and the benefit it provided.

4 Xcode shortcuts to boost your productivity for SwiftUI

Leaning tips and tricks about the tool will help you down the road. Today, I will show you 4 Xcode shortcuts that I find helpful when dealing with SwiftUI.

How to set a screen's background color in SwiftUI

Setting background color in SwiftUI is not as straightforward as UIKit. Let's learn how to do it.

How to resize an image view to fit a container view in SwiftUI

Learn how to fit an image view to any container.

Replicate 12 UIKit's contentMode options in SwiftUI

In UIKit, we have various ways to control an image's position and behavior in UIImageView with a help contentMode property. In SwiftUI, we only have fit and fill content mode. Let's see how we can replicate the rest.

How to add background to your view in SwiftUI

Learn how hard or easy it is to add a background view in SwiftUI.

How to preview a device in landscape orientation with SwiftUI Previews

SwiftUI doesn't have a built-in way to preview for a device in landscape orientation at the moment, but we can simulate that with a few modifiers.

NSAttributedString in SwiftUI

Find out what is the SwiftUI way of styling portions of text.

How to resize and position an image in UIImageView using contentMode

Learn thirteen ways to position and resize UIImage in UIImageView.

How to initialize @StateObject with parameters in SwiftUI

@StateObject is an essential property wrapper in SwiftUI, but I found the way to initialize them is not obvious.

What is the difference between Tuist init and scaffold

A brief summary of init and scaffold commands.

How to resize a SwiftUI Image and keep its aspect ratio

Learn how to use aspect fit and aspect fill content mode to fit your image to its bounds.

Tuist scaffold: How to use the Tuist template to create a new module for an ongoing project

Learn how the scaffold command helps you to bootstrap new components or features such as a new VIPER module or a new framework for your new feature.

How to fix ZStack's views disappear transition not animated in SwiftUI

Show and hide transition animation in ZStack can be glitchy. Learn how to fix it with a simple trick.

Tuist init: How to use Tuist templates to bootstrap your project

Learn how to use, and limitations of tuist init, a command that bootstrap a new project.

Tuist Template: What is it and how to create them

The template is a way to group repetitive code structure into a reusable component. You will learn how to create them in this article.

Using App Store Connect API with Fastlane Match

Apple announced the App Store Connect API back in WWDC18. It provides an official way to interact with App Store Connect, and Fastlane already supports this. With a recent 2FA enforcement from Apple, it is time for you to adopt it.

How to fix "no identity found - Command CodeSign failed with a nonzero exit code" error in Xcode

There might be several reasons that cause this error. I will share one that just happened to me.

Sort array of objects by multiple properties with Swift Tuple

Learn how tuple can help you in sorting.

How to create segmented control in SwiftUI

Learn the way to create the UISegmentedControl equivalent in SwiftUI.

How to add a unit test target to a Tuist project

We will see how hard (or easy) it is to add a new unit testing bundle target to your Xcode project with Tuist.

How to delete UserDefaults data on macOS and Catalyst

In iOS, if you want to delete the app's UserDefaults, you can simply delete the app. But that is not the case for macOS and Catalyst app.

How to use SwiftUI Picker

Learn how to use Picker, a UIPickerView equivalent for SwiftUI.

Does Swift enum retain its associated value

An easy question that you might overlook. Learn this simple fact together in this article.

Record iOS Simulator video as mp4 and GIF with Xcode

Xcode 12.5 brings many great updates and features. One of them is the ability to record a video of the app directly from the Simulator app.

Navigation in SwiftUI

Part 4 in the series "Building Lists and Navigation in SwiftUI". We will explore a NavigationView, UINavigationController equivalent in SwiftUI.

Getting Started with Tuist

A brief introduction to Tuist, a command-line tool that helps you generate Xcode projects.

How to resize an UIImageView to fit a container view using auto layout

Learn how to fit image view to any container by changing Content Hugging Priority and Content Resistance Priority.

How to sort by multiple properties in Swift

Learn how to sort an array of objects with multiple criteria.

List view, a UITableView equivalent in SwiftUI

Part 3 in the series "Building Lists and Navigation in SwiftUI". We will explore a List, UITableView equivalent in SwiftUI.

How to create custom operators and do operators overloading in Swift

Learn how to overload existing operators such as +, -, *, / or create a custom one (such as .^.).

How to use ScrollView in SwiftUI

Part 2 in the series "Building Lists and Navigation in SwiftUI". We will explore a ScrollView, UIScrollView equivalent in SwiftUI.

What is @Environment in SwiftUI

Learn how SwiftUI shares application settings and preference values across the app.

Create a list of views in SwiftUI using ForEach

Part 1 in the series "Building Lists and Navigation in SwiftUI". We visit the first building block of any list view, content, and how to create them.

Different ways to check if a string contains another string in Swift

Learn how to check if a string contains another string, numbers, uppercased/lowercased string, or special characters.

Different ways to compare string in Swift

String comparison is an essential operation for day to day job. Swift provides a few variations for this. We will visit them in this article.

TextField in SwiftUI

How to create and use TextField in SwiftUI.

How to change the color of SF Symbols

SF symbols are icon sets that Apple design to work with their system font. Learn how to change its color and how to show them in multicolor style.

How to fix "Skipping duplicate build file" warning in Xcode

There might be several reasons that cause this error. Here are the solutions that fix it for me.

How to convert a String to an Int in Swift

Learn to convert a string "123" to an integer 123.

2020 Review

A look back at 2020.

Different ways to sort an array of strings in Swift

Learn a proper way to sort an array of strings in each circumstance.

How to specify fractional digits for formatted number string in Swift

Learn how to format a Float and Double string.

How to use DateFormatter in Swift

Learn how to use this expensive DateFormatter.

How to loop in Swift

Learn different ways of using for loop for each scenario.

How to fix "Build input file cannot be found" error in Xcode

There might be several reasons that cause this error. I will share one solution that fixes the one that happened to me the most.

How expensive is DateFormatter

If you are working on iOS for long enough, there is a chance that you might have known that DateFormatter is expensive, but what is costly about DateFormatter? Let's find out in this article.

How to get the first N elements of array in Swift

Learn a few ways to do it and things you should know when using them.

UIStackView padding

Learn how to add padding to your stack view's content.

Custom UIStackView spacing

Learn a lesser-known API to create a custom UIStackView spacing without nested them together.

Scaling custom fonts automatically with Dynamic Type

Font is an essential part of an app. A good selection of font would make your app stand out from the crowd. But whatever fonts you choose, you have to make sure it doesn't lose its core function, readability. You might feel reluctant to use a custom font in the past because you might lose the benefit of dynamic type goodness that Apple provides with their system font. Since iOS 11, this is no longer the case. You can easily use your custom font dynamic type.

Multi-cursor editing in Xcode

It is a hidden gem in Xcode that can save up your coding time. Learn what it is, how to use it, and some use cases.

Getting the number of days between two dates in Swift

There are a few variations when dealing with counting days. You need to ask yourself some questions beforehand.

Understanding Date and DateComponents

Date and time might be among your list of the hardest things in programming (It is for me). Today, I'm going to talk about a basic concept of a Date and its companion DateComponents.

What is @escaping in Swift closures

Learn the meaning of @escaping, so you know what to do when you see it or when you need to write one.

Better print debugging with Xcode breakpoints

Print debugging is the simplest form of debugging technique, but it possesses some drawbacks. Let's see how we can make it better by using Xcode breakpoints.

Reduce boilerplate code with an automatic synthesis of Equatable and Hashable conformance

Equatable and Hashable are two essential protocols in the Swift world. Let's learn an old Swift feature that you might forget.

Setting default values for NSUserDefaults

NSUserDefaults is a go-to database for saving users' preferences. Learn how to populate it with your default values.

How to save/export an image in Mac Catalyst

Learn how to lets users save an image outside of your app’s sandbox.

3 lesser-known ways of using Swift enums

Three language features around Swift enumeration that you might not aware of.

Testing delegates and protocols in XCTest

Learn how to write unit tests for delegate/protocol methods.

Make a placeholder view in SwiftUI with redacted()

SwiftUI provides an easy way to convert to render any view into a placeholder style by redacting its content.

Move your view around with Drag Gesture in SwiftUI

SwiftUI's UIPanGestureRecognizer equivalent.

Quick way to open a Custom URL Scheme in iOS Simulator

In the past, the way I test a custom URL scheme is to go to Safari and open up any of my custom URLs. If you are still doing that, there is a better alternative.

How to renew an expired certificate with Fastlane Match

Fastlane Match saves us a lot of time managing certificates and provisioning profiles, but there is one thing that we have to do it manually. That is a renewal expired certificate. Luckily, we have to do it once a year. Let's learn how to do it.

How to Add inline images with text in SwiftUI

In iOS 14, we have a new way to put images along with texts.

How to declare Swift protocol for a specific class

Learn how to create protocols that constrain their conforming types to a given class.

A new way to manage the back button title in iOS 14 with backButtonDisplayMode

Apple adds a new way to control where the back button will pick up its title. Let's see how this make thing a lot easier going forward.

SVG image assets supported in Xcode 12

We finally get SVG supported and the best thing is it is backward compatible with some limitations.

What should you know about a navigation history stack in iOS 14

In iOS 14, long-press on the back button will bring up a history stack. Learn what you should consider with this new behavior.

Cross-promote apps with SKOverlay

SKOverlay is a new tool from Apple for doing apps cross-promotion.

UIToolbar in SwiftUI

In iOS 14, we finally have a way to set a toolbar for a view in a navigation view.

Custom navigation bar title view in SwiftUI

Learn how to set a navigation bar title view in SwiftUI.

A first look at matchedGeometryEffect

This modifier can interpolate position and size between two views. This is one of the most exciting features for me. Let's see what is capable of in this beta.

Should I learn UIKit or SwiftUI

The most popular question since the introduction of SwiftUI. Here is my thought after WWDC20.

Add custom SwiftUI view to View Library with LibraryContentProvider

A new way to create a reusable view.

SwiftUI's Toggle Customization

How to create a reusable toggle style in SwiftUI.

Easy way to detect a retain cycle in a view controller

A view controller is one component where memory leak usually takes place since it holds many pieces together. One of the easiest ways to detect them is to see if a view controller is not being deallocated. Let's see how Xcode breakpoint can help you find a leak.

Sleep sort: A sorting algorithm without compare

I can't tell it is a stupid or genius algorithm, but it sure got a beauty in it.

Animation delay and repeatForever in SwiftUI

Explore how delay and repeatForever affect an animation.

How to request a user's location

Learn the proper way of getting user information.

What is backIndicatorTransitionMaskImage

To set a custom image for the back button, we need to set an image to both backIndicatorImage and backIndicatorTransitionMaskImage, but what does backIndicatorTransitionMaskImage really mean?

How to change a back button image

Learn how to change a UINavigationBar back button indicator.

Responsive design with UIStackView

Learn how UIStackView can help to make your UI adapt to size change.

Match a view's shadow to the Sketch shadow

Learn how to set shadow spread and blur from a Sketch design.

Different ways to check for String suffix in Swift

Learn how to get a suffix from a Swift string.

Decode an array with a corrupted element

When working with an unstable, legacy, or third party API, you might get a malformed object in an array. Learn how to decode a JSON array with corrupted data in Codable safely.

How to set cornerRadius for only some corners

Learn to round specific corners, e.g., top-left and top-right.

How to set status bar style

Learn different ways to control the status bar style.

Different ways to check for String prefix in Swift

Learn how to get a prefix from a Swift string.

How to compare two app version strings in Swift

Learn how to check your app version strings are higher or lower.

How to split a string into an array of substrings in Swift

Learn different ways to split a string into an array of substrings.

How to make multi-line text in UIButton

The default appearance of UIButton is a single line text, but it also supports a multi-line text with some minor tweak.

History of Auto Layout constraints

Learn different ways to define Auto Layout constraints programmatically.

How to preserve a struct memberwise initializer when you have a custom initializer

A tip to declare a custom initializer without losing a memberwise initializer.

Memberwise Initializers for Structure Types

Struct is one of the basic building blocks in your app. Today I'm going to share some tips about memberwise Initializers.

How to display HTML in UILabel and UITextView

When you work with an API, there would be a time when your backend wants to control a text style, and HTML is the most common format for the job. Do you know that WKWebView is not the only way to present HTML string? Learn how to render it in UILabel and UITextView.

How to remove text from a navigation bar back button

There are a lot of hacky ways to modify or remove a back button title. This tip will show you how to do it properly.

Useful Xcode shortcuts for unit testing

Testing is a process we do along with our development. Knowing shortcuts would help you save some time, which will add up in the long run.

tintColor in SwiftUI

We will talk about accentColor, a tintColor equivalent in SwiftUI.

tintColor

Introduce you to one of an essential part of iOS theming. What is tintColor and its benefit.

SwiftUI ButtonStyle

How to create a reusable button style in SwiftUI.

SF Symbols: What is it, and how to use?

Introduction of SF Symbols, learn the basics, and how to use them.

How to create code snippets in Xcode

Create a reusable boilerplate snippet that you can use in the project.

Class-only Protocols: class or AnyObject

If you are still declaring class-only protocols by inheriting them from class, you might need to revise your knowledge.

How to create Neumorphic design in SwiftUI

Neumorphism or Neomorphism is a new design trend of UI recently. We are going to see how to implement this in SwiftUI.

How to remove Cocoapods from your project

Swift Package Manager is getting better every day. It is a matter of time before everyone supports it. When the time comes, make sure you know how to say goodbye to this old friend.

How to read a Property List (plist) into the code

When I want to keep some information or configuration out of a code base and don't want something fancy, I usually save it as Property List file. Let's see how to do it.

How to create a new Xcode project without Storyboard

Modify AppDelegate or SceneDelegate to support a non-storyboard approach.

How to create Activity Ring in SwiftUI

A guide to creating an activity-ring-like circular progress bar in SwiftUI. An in-depth tutorial of what I think when making a custom view. At the end of this article, you will be able to create the Activity ring used in the Activity app on Apple Watch.

Testing Remote Push Notification in iOS simulator

A new and easier way to test Apple push notification on iOS simulator.

Gradient in SwiftUI

SwiftUI has built-in ways to apply gradient color to its view. We are going to explore all three types of gradients provided, LinearGradient, RadialGradient, and AngularGradient.

SwiftUI basic Shape operations

Most complex custom views can be made by composing many basic shapes together. Today we will learn basic operations that we can do with them. It may seem trivial, but knowing these basics will benefit you in the future.

Intrinsic content size in SwiftUI

How to define intrinsic content size in SwiftUI

Sign in with Apple Tutorial, Part 4: Web and Other Platforms

Part forth in a series Sign in with Apple. Use Sign in with Apple JS to let users set up accounts and sign in to your website and apps on other platforms.

Print unescaped string output in Swift

How to print object (po) in a debugger (lldb) without escape special characters.

Sign in with Apple Tutorial, Part 3: Backend – Token verification

Part 3 in a series Sign in with Apple. In this part, we will see how backend can use the token to sign up/sign in users.

Inset grouped List in SwiftUI

How to make .insetGrouped UITableView style in SwiftUI List

What is @discardableResult

Learn about this Swift attribute and its purpose.

Sign in with Apple Tutorial, Part 2: Private Email Relay Service

Part 2 in a series Sign in with Apple. In this part, we will talk about the anonymous email address. How to make it work and its limitation.

SwiftUI Animation

Explore how to animate changes in SwiftUI.

Sign in with Apple Tutorial, Part 1: Apps

Part 1 in a series Sign in with Apple. In the first part, we will focus on the app part. What we need to do to add Sign in with Apple option in our app.

Manually symbolicate crash reports

A guide to decode a gibberish crash report to a human readable format.

Swift Documentation

How to write documentation comments in your Swift code.

Unwrap optional values in XCTest with XCTUnwrap

No more manual if let and guard let in your tests.

// MARK: - What is it?

If this is just a comment for you, this article might benefit you.

Caching dependencies in Github Actions

How to cache Pods, Ruby gem, and Carthage in your iOS project.

Dark color cheat sheet

A cheat sheet that tells you what colors to use to support dark mode. This is a guide for those who want to adopt dark mode, but too lazy to figure out which color to use.

Github Actions for iOS projects

How to setup ci for iOS projects with Github Actions.

if let: How not to use it

Learn how you should write a code that shows your true intention.

Dark color

Things you should know about color when adopting dark mode.

Take a screenshot and record a video in iOS Simulator

Learn how to do all of this without any external tools.

UINavigationBar changes in iOS13, Part2: UISearchController

Revisit of navigation bar appearance — this time with a UISearchController. If you have a search bar in your navigation bar, you might need to recheck when you build your app against iOS13.

Data in SwiftUI, Part 3: Tools

The last part in a series on understanding data in SwiftUI. See all tools SwiftUI provided to declare different types of data and dependency. Learn when and how to use @State, @Binding, ObservableObject, @ObservedObject, @EnvironmentObject, and @Environment.

Data in SwiftUI, Part 2: Views as a function of data

Part 2 in a series on understanding data in SwiftUI. We will talk about the key that makes principles in part 1 possible in SwiftUI. And how this resulting in a reduction of the complexity of UI development.

Data in SwiftUI, Part 1: Data

Part 1 in a series on understanding data in SwiftUI. In the first part, we will try to understand the importance of data and how they play an essential role in SwiftUI.

UIRefreshControl with new card style modal

Make sure your refresh control working on iOS 13.

Create a new iOS12 project in Xcode11

Required modifications to make your newly created project work in iOS 12 or lower.

UINavigationBar changes in iOS13

Apple brings a lot of appearance changes in iOS13, and the navigation bar is one of them. Cover everything you should know once you build your app against iOS13 (Xcode11).

Adopting iOS Dark Mode

A long-awaited feature has finally come to iOS. Join it or not is your choice to make. This article will guide you through it.

Modality changes in iOS13

In iOS13, the modal presentation gets a new look and dismissal gesture. This article will talk about what you can do with these new welcoming changes.

Custom UIHostingController

Learn how to create a custom subclass of UIHostingController and its benefit.

SwiftUI's ViewModifier

Learn a crucial concept in SwiftUI, view modifier, and a guide of how to create your custom modifier.

SwiftUI changes in Xcode 11 Beta 5

Highlight changes for SwiftUI in beta 5

How to use SwiftUI in UIKit

Using SwiftUI as UIView and UIViewController

SwiftUI changes in Xcode 11 Beta 4

Highlight changes for SwiftUI in beta 4

Better dependency injection for Storyboards in iOS13

Say goodbye to optional properties in your view controllers. In iOS13, you can inject those properties at a time of view controller creation.

UISplitViewController in SwiftUI

WWDC session shows us a way to create UISplitViewController with NavigationView in SwiftUI. It finally works in Xcode 11 Beta 3.

SwiftUI changes in Xcode 11 Beta 3

Highlight changes for SwiftUI in beta 3

How to use UIKit in SwiftUI

Using UIView and UIViewController in SwiftUI

Browse SF Symbols on Mac

SF Symbols contain over 1,500 icons. It would be hard if you don't know the existence of SF Symbols App.

MVC (Missing View Controller)

Where is UIViewController in SwiftUI?

Introduction to Coordinator

iOS flow controller

Enum & custom type from primitive JSON type

Swift Codable

Codable in Swift 4.0

Can it replace JSON encode/decode lib out there?

Where is my getter/setter in Swift?

A missing Objective-C piece