Khoa Pham
Khoa Pham

Ohayo

Swift Discovery

Discover all the tech

Featured

My year in review 2020

Issue #715

I remember this time last year in December 2019, I spent almost every single bit of my free time on Puma because I want a Swift friendly version of fastlane that suits my need and leverages Swift 5 features.

Here’s my review of my …

How to use playground in Swift file

Issue #998

Traditionally, if we wanted to quickly test a function or a piece of logic, we would open a separate Playground file (.playground).

From Xcode 26 we can have access to the new #Playground macro in Swift 6.2. This allows us to declare a …

How to morph liquid glass view transition

Issue #997

An interesting feature in iOS 26 is the ability to create morph “Liquid Glass” effects, where views with the .glassEffect() modifier can fluidly morph into one another. This is achieved using GlassEffectContainer and the …

How to prompt users to configure widgets in iOS 18

Issue #996

When creating widgets for iOS, especially those that need user input to be useful, one common challenge is guiding the user to configure them. Before iOS 18, a user would add a widget, but then would have to know to long-press it and …

How to make zoom transition animation in iOS 18

Issue #995

With iOS 18, SwiftUI introduces matchedTransitionSource and navigationtransition as a powerful new way to create zoom animations between views. This allows you to smoothly transition from a small view to a larger, more detailed view, …

How to create mesh gradient in iOS 18

Issue #994

With iOS 18, Apple introduced a powerful new tool for creating beautiful, dynamic backgrounds: MeshGradient. Forget simple two-color gradients; mesh gradients let you blend a whole grid of colors together smoothly, creating stunning, …

How to animate number change from iOS 17

Issue #993

Before iOS 17, if you wanted to animate a number changing, SwiftUI would just fade the old number out and fade the new one in. It worked, but it wasn’t very exciting.

Here’s how that looked:

struct OldCounterView: View {
    @ …

How to observe model changes in iOS 26

Issue #992

In the past, making your screen update when data changed in UIKit meant writing extra code, either with didSet, Combine or some other callbacks. Now, it’s automatic.

With the latest iOS 26 updates, UIKit can automatically watch your …

How SwiftUI StateObject and React useState defer initial value evaluation

Issue #991

When building apps in SwiftUI or React, we often need to store values that change — like a counter, user input, or a list of items.

To do this:

  • React gives us useState.
  • SwiftUI gives us @State and @StateObject.

But here’s something cool: …

How to tap again on tab bar item to scroll top in iOS

Issue #990

In many popular apps like LinkedIn, Reddit, we can tap again on a bar bar item to scroll to top. Although this behavior is not built in by iOS, we can implement that very easily.

The idea is to keep track of previous selection so we can …

How to make NSImage Sendable in Swift

Issue #989

In Swift 6, Apple introduced stricter rules to help make your code safer when using concurrency (like async, await, Task, and actor). These rules check that types used in concurrent code are safe to share across threads.

Types that are …

How to observe optional ObservableObject in SwiftUI

Issue #988

When working with Core Data, there are times we have optional NSManagedObject to pass around. These objects conform to ObservableObject, and in SwiftUI we can’t @ObservedObject on optional ObservableObject

One way we can workaround …

How to clear background for TextField inside list in macOS

Issue #986

When using TextField in SwiftUI List on Mac, it has unwanted background color when focused. We can turn it off using introspection or a custom TextField wrapper

TextField("Search", text: $searchText)
    .introspect(.textField, on: …

How to use GitHub Copilot for Xcode

Issue #985

During GitHub Universe 2024, GitHub announced that GitHub Copilot code completion in Xcode is available in public preview. The project is open source at CopilotForXcode

image

GitHub Copilot has been available as VS Code extension for a while, …

How to conditionally render widgets in iOS

Issue #984

The WidgetBundle lets us expose multiple widgets from a single widget extension

It uses WidgetBundleBuilder to constructs a widget bundle’s body.

In iOS 18, if we include ControlWidget then we need to check iOSApplicationExtension iOS 18. …

How to open app with Control Widget on iOS 18

Issue #983

In iOS 18, we can make Control Widget in Widget extension

import WidgetKit
import SwiftUI

@available(iOS 18.0, *)
struct BookControlWidget: ControlWidget {
    var body: some ControlWidgetConfiguration {
        StaticControlConfiguration …

How to use NSFetchedResultsController memory wise in Core Data

Issue #982

If you’re using NSFetchedResultsController in Core Data, it might take up a lot of memory, especially when working with large datasets. To keep your app running smoothly, it’s important to manage memory efficiently

Use Fetch Limits and …

How to use NSDragOperation

Issue #981

NSDragOperation represent which operations the dragging source can perform on dragging items.

There are several types of drag operations, and each one has a different purpose and visual cue.

Copy Operation .copy

  • What It Does: The item …

How to make NSCollectionView with diffable data source and SwiftUI

Issue #980

NSCollectionView, available since macOS 10.5+, is a good choice to present a list of content. Let’s make a SwiftUI wrapper for NSCollectionView with diffable data source and compositional layout

Use NSViewControllerRepresentable …

How to use React Query useQuery with debounce

Issue #979

When dealing with user input, such as in an autocomplete component, it’s common to implement debouncing to reduce the number of API calls and improve the user experience.

React Query’s useQuery hook makes it easy to manage the …

How to handle tap gesture in SwiftUI Charts

Issue #978

From iOS 17, SwiftUI Charts has chartGesture, together with SpatialTapGesture we can check tap location and convert that to Charts value

Chart {}
    .chartGesture { chart in
        SpatialTapGesture()
            .onEnded { value in …

Khoa Pham

Hello, I’m Khoa

I’m a thinker and storyteller with a passion for exploring the intersection of creativity and technology

🧑‍💻 I love crafting high quality and useful apps
🔥 I love open source. My GitHub open source has 2.3k followers with packages that are integrated by 45k+ apps and over 3.4m+ downloads on CocoaPods.
✍️ I write here on my blog and on Medium, which has over 2.7k+ followers with tons of articles and 90k+ monthly views.
🖥 Follow me for sharings about Swift, SwiftUI, iOS and macOS development.
Hei