iOS Development

iOS 17 and Swift 5.9: Macros, the Observation Framework, and SwiftData

WWDC 2023 delivered one of the richest API updates in Apple’s recent history. Swift 5.9’s macro system fundamentally changes how boilerplate is eliminated, the Observation framework replaces ObservableObject with a simpler model, and SwiftData brings a Swift-native persistence framework to replace Core Data for new projects.

Swift Macros

Swift macros are compile-time code generators. Unlike preprocessor macros in C, Swift macros are type-safe and syntax-aware. The most impactful built-in macro is @Observable:

// Before iOS 17 (ObservableObject)
class UserProfile: ObservableObject {
    @Published var name: String = ""
    @Published var bio: String = ""
}

// iOS 17 — @Observable macro generates all the observation infrastructure
@Observable
class UserProfile {
    var name: String = ""
    var bio: String = ""
}

The Observation Framework

The @Observable macro generates property-level observation — SwiftUI only re-renders the parts of the view that read the specific property that changed. With ObservableObject/@Published, any published property change triggered a full re-render of every view observing the object.

// In a SwiftUI View
struct ProfileView: View {
    // No @ObservedObject or @StateObject needed — just reference it
    var profile: UserProfile

    var body: some View {
        TextField("Name", text: $profile.name) // automatic observation
    }
}

SwiftData: Swift-Native Persistence

SwiftData is Core Data reimagined for the Swift + SwiftUI world. Define your model with a macro:

import SwiftData

@Model
class Post {
    var title: String
    var body: String
    var createdAt: Date
    var tags: [String]

    init(title: String, body: String) {
        self.title = title
        self.body = body
        self.createdAt = .now
        self.tags = []
    }
}

// In your App entry point
@main
struct MyApp: App {
    var body: some Scene {
        WindowGroup { ContentView() }
            .modelContainer(for: Post.self) // sets up the store
    }
}

TipKit: In-App Feature Discovery

TipKit is Apple’s framework for surfacing contextual tips to users when they are most relevant:

struct SearchTip: Tip {
    var title: Text { Text("Try Advanced Search") }
    var message: Text? { Text("Use filters to find exactly what you need.") }
    var image: Image? { Image(systemName: "magnifyingglass.circle") }
}

// Show inline or popover in any SwiftUI view
TipView(SearchTip())

Xcode 15 Developer Experience

Xcode 15 introduces string catalogs (.xcstrings) for localisation, bookmarks in the source editor, and dramatically faster build times via improved parallelisation. The simulator now supports specific iOS 17 hardware features for testing.

The Swift 5.9 and iOS 17 release marks a platform maturation milestone. The simplification from ObservableObject to @Observable and from Core Data to SwiftData represents Apple learning from years of developer feedback. Now is a great time to be building for Apple platforms.

Share this post:
Copied!

Leave a Comment

Your email will not be published.

READY TO BUILD?

Let's Build Something
Amazing Together

Tell us about your project. We'll have a proposal in your inbox within 24 hours.

Free Consultation
NDA Available
Fixed-price Options
Dedicated PM