Migration Checklist
When updating legacy SwiftUI code to iOS 17+:
- Replace
ObservableObjectwith@Observable - Remove all
@Published(regular properties auto-publish) - Replace
@StateObjectwith@State - Replace
@ObservedObjectwith@Bindable - Replace
environmentObject(_:)withenvironment(_:) - Replace
@EnvironmentObjectwith@Environment(Type.self) - Update
onChange(of:perform:)toonChange(of:initial:_:) - Replace
.onAppear { Task {} }with.task
Before & After Example
Before (iOS 16)
class UserProfileModel: ObservableObject {
@Published var name: String = ""
@Published var email: String = ""
}
struct ProfileView: View {
@StateObject private var model = UserProfileModel()
var body: some View {
TextField("Name", text: $model.name)
.onAppear {
Task {
await model.load()
}
}
}
}After (iOS 17+)
@Observable
class UserProfileModel {
var name: String = ""
var email: String = ""
}
struct ProfileView: View {
@State private var model = UserProfileModel()
var body: some View {
TextField("Name", text: $model.name)
.task {
await model.load()
}
}
}