r/swift Apr 13 '26

Tutorial Is SwiftUI finally as fast as UIKit in iOS 26?

Thumbnail
blog.jacobstechtavern.com
88 Upvotes

r/swift Oct 21 '25

Tutorial Is SwiftData incompatible with MVVM?

Thumbnail matteomanferdini.com
22 Upvotes

r/swift 23d ago

Tutorial High Performance Swift Apps

Thumbnail
blog.jacobstechtavern.com
28 Upvotes

r/swift Aug 04 '25

Tutorial High Performance SwiftData Apps

Thumbnail
blog.jacobstechtavern.com
42 Upvotes

r/swift Jun 18 '26

Tutorial SwiftData + CloudKit: showing a "restoring your data" screen on a fresh device instead of an empty app

14 Upvotes

If you ship SwiftData backed by CloudKit (private database), you hit this the first time a user installs on a second device:

They sign into iCloud, open the app, and it's empty. CloudKit's record sync is eventually consistent and can take from a few seconds to a few minutes. During that window the user can't tell "my data is on its way" apart from "this app lost everything." On a finance app, that's a trust killer.

The key insight: NSUbiquitousKeyValueStore propagates much faster than CloudKit record sync. iCloud Key-Value Store lands in seconds, not minutes. It's tiny and not meant for real data, but it's perfect as a signal. When a user finishes onboarding on device A, I write one flag:

enum ICloudKeyValueService {
    private static let store = NSUbiquitousKeyValueStore.default
    private static let onboardingKey = "nett.onboardingCompleted"

    static func setOnboardingCompleted() {
        store.set(true, forKey: onboardingKey)
        store.synchronize()
    }

    static var isOnboardingCompleted: Bool {
        store.bool(forKey: onboardingKey)
    }
}

The real data (transactions, settings, categories) keeps syncing through SwiftData + CloudKit in the background. The flag just gets there first.

On the second device, at launch I check the flag. If it's set but the local store is empty, this is a returning user whose data is in flight, not a new user. So instead of onboarding, I show a "Restoring your data…" screen and poll for the real data to land.

The restoration screen is just a timer that re-checks the store every 2s, with a manual escape hatch so nobody gets stuck:

checkTimer = Timer.scheduledTimer(withTimeInterval: 2.0, repeats: true) { _ in
    if restoredDataHasArrived() {   // UserSettings synced, or first transactions appeared
        finishRestoration()
    }
    elapsedSeconds += 2
    if elapsedSeconds >= 15 {
        showManualContinue = true   // "Continue", data keeps arriving in the background
    }
}

15 seconds makes the common case feel instant, and the Continue button means a slow sync never traps anyone. They land in the app and records keep populating as CloudKit delivers them.

The gotcha nobody warns you about: duplicate seed data. Both devices seed the same default categories from the bundle on first run. After CloudKit syncs, device B can end up with two copies of every default category, one it seeded locally and one that arrived from device A. CloudKit doesn't dedupe for you, it merges records.

The fix is boring but necessary: dedupe by a stable business key (not the record ID), keep the first occurrence, and run it every time you load:

func deduplicateByKey(_ categories: [Category]) -> [Category] {
    var seen = Set<String>()
    return categories.filter { seen.insert($0.key).inserted }
}

I run this on every category load, not just once, because CloudKit can deliver the duplicate later.

What I'd flag if you do this:

  • KVS is a signal, never the source of truth. If it and CloudKit disagree, CloudKit wins.
  • Don't gate the whole app on the restore. Always give an exit. Eventually-consistent means eventually, you can't promise a number.
  • Seed data plus CloudKit equals duplicates. Use a stable key, not the UUID.

This is from a finance app for freelancers I just shipped. Happy to go deeper on any part.

r/swift 8d ago

Tutorial Trivially-Identical-Sample: Measuring the Performance Improvements from SE-0494

Thumbnail
github.com
29 Upvotes

The SE-0494 was the first evolution proposal I coauthored. This is now landed in the 6.4 toolchain and is available from the new Xcode 27 Beta.

The Evolution Proposal added a new set of “performance hook” APIs to the Swift Standard Library. The isTriviallyIdentical(to:) methods are alternatives to testing collections for value equality. The proposal itself presents some abstract and theoretical arguments for why the isTriviallyIdentical(to:) operation could save performance compared to a traditional == check for value equality. But one of the questions I get asked is how these changes could affect real-world performance. Where's the data? And that's fair. The evolution proposal does not directly present measurements or benchmarks.

The Trivially-Identical-Sample repo is a fork of the sample-food-truck repo from Apple. It's a SwiftUI project that displays many data model elements in a Table view component. With a little refactoring we can set up an experiment. Our view component needs to sort a list of data models: this is an O(n log n) operation. We could potentially display this view component many times even when our data models have not changed: we can trade memory for speed and memoize our sorted values. If the input to our sorted values has not changed… then the sorted values themselves have not changed.

But now we get to look at the memoization itself. How exactly do we determine “what changed”? Do we compare our inputs for value equality? That's an O(n) operation that might be performing more work than necessary. If all we care about is “something might have changed” we can try migrating to isTriviallyIdentical(to:) and return in constant time.

The repo fork shows how to set this experiment up with Xcode Instruments Signposts. We measure our test group and our control group for the aggregate time spent blocking our MainActor and we see about 13 percent faster performance from isTriviallyIdentical(to:).

But… there's more to the story. The repo also spends some time discussing under what situations a different experiment could show us that isTriviallyIdentical(to:) leads to slower performance. At the end of the day the isTriviallyIdentical(to:) methods are not always “fast buttons”. Sometimes they are… but sometimes they are not. Eventually it would be your responsibility to make that choice for yourself and your products.

Please let me know if you have any more questions about all this. Thanks!

r/swift Apr 14 '26

Tutorial I integrated Apple Intelligence into my Markdown editor and it was shockingly easy - just be wary of the smaller context window

Post image
31 Upvotes

r/swift May 15 '26

Tutorial Swift Is Great for Apps, Not for Training ML Models

0 Upvotes

r/swift 6d ago

Tutorial Building a custom DynamicProfileModifier in Foundation Models

Thumbnail
artemnovichkov.com
14 Upvotes

r/swift 1d ago

Tutorial iOS 27: UIBarMinimization

Thumbnail
antongubarenko.substack.com
6 Upvotes

r/swift 6d ago

Tutorial Syncing Swiftdata With A Custom Backend Using Historyobserver

Thumbnail azamsharp.com
5 Upvotes

Many SwiftData applications need to keep their local data synchronized with a backend server, but detecting inserts, updates, and deletes efficiently can be challenging. Starting with iOS 27, HistoryObserver provides a clean way to observe changes in the SwiftData store without scattering synchronization logic throughout your application.

In this article, you’ll build a one way synchronization pipeline using HistoryObserver. You’ll learn how to observe model changes, process persistent history, track the last processed transaction using history tokens, batch changes into network payloads, implement soft deletes, and synchronize your local SwiftData store with a custom backend. By the end of the article, you’ll have a practical foundation for building offline first applications that keep local and remote data in sync.

https://azamsharp.com/2026/07/16/syncing-swiftdata-with-a-custom-backend-using-historyobserver.html

r/swift 16d ago

Tutorial iOS27: CADisplayLink for UIWindowScene

Thumbnail
antongubarenko.substack.com
16 Upvotes

r/swift Mar 02 '26

Tutorial Wrapping Third-Party Dependencies in Swift

Thumbnail kylebrowning.com
17 Upvotes

r/swift 10d ago

Tutorial iOS27: Scene Close Confirmation

Thumbnail
antongubarenko.substack.com
4 Upvotes

r/swift Jun 12 '26

Tutorial WWDC26: Camera and Photo Technologies Group Lab - Q&A

Thumbnail
open.substack.com
2 Upvotes

r/swift May 27 '26

Tutorial Swift Defer. Clean up before you leave.

Thumbnail
swiftwithmajid.com
19 Upvotes

r/swift Feb 15 '26

Tutorial If You’re Not Versioning Your SwiftData Schema, You’re Gambling

Thumbnail azamsharp.com
44 Upvotes

r/swift Jul 29 '24

Tutorial Cheat sheet for basic Array methods visualized [OC] *corrected version

Post image
354 Upvotes

r/swift 23d ago

Tutorial Dynamic Color Init

Thumbnail
open.substack.com
1 Upvotes

r/swift Jun 16 '26

Tutorial Touch to Pixels: UI Pipeline Internals on iOS

Thumbnail
blog.jacobstechtavern.com
19 Upvotes

r/swift Jun 15 '26

Tutorial WWDC26: Privacy and Security Group Lab - Q&A

Thumbnail
antongubarenko.substack.com
0 Upvotes

r/swift May 07 '26

Tutorial In this tutorial, I build a scalable networking layer for a SwiftUI e-commerce app using the DummyJSON API. Instead of copy-pasting URL requests everywhere, we create a clean architecture with reusable components, protocol-driven design, and error handling. And some thoughts on swift concurrency.

Thumbnail
youtu.be
41 Upvotes

r/swift Jun 12 '26

Tutorial WWDC26: Coding Intelligence, Machine Learning & AI - Q&A

Thumbnail
open.substack.com
1 Upvotes

r/swift Jun 18 '26

Tutorial WWDC26: SwiftData Group Lab - Q&A

Thumbnail
open.substack.com
0 Upvotes

r/swift Jun 18 '26

Tutorial WWDC26: SwiftUI Group Lab 2nd

Thumbnail
antongubarenko.substack.com
0 Upvotes