Skip to content

Introducing ObservableConverter

A plugin to help convert to @Observable

by Brian Capps
A logo for the ObservableConverter plugin with arrows inside braces on a pink app icon.

At WWDC 2023, Apple introduced the brand new @Observable macro, a simple way to define a type with properties that will automatically update SwiftUI views when they change, replacing the Observable​Object protocol and @Published properties. This new feature is great, but what should we do with all of our old types that use Observable​Object and outdated property wrappers like @State​Object, @Observed​Object, and @Environment​Object? To kickstart this conversion in Xcode, we at Lickability started writing a small tool and are releasing the first beta today: ObservableConverter.

Logo lockup: ObservableConverter by Lickability

ObservableConverter is a Swift command plugin that, when installed from Xcode 15, makes converting from Observable​Object to using @Observable literally just a few clicks after adding the dependency. Select your target in the project navigator, right click, and select Convert Target to Use @Observable. It will update your Observable​Objectclasses, convert all the old property wrappers, and make some view modifier updates. From the plugin’s executable, we make use of Apple’s Swift​Syntax to get a view of the syntax tree for each file and make some safe replacements and modifications. Once you run the conversion, you can simply remove the dependency entirely!

The tool is still very much in beta, so while it covers converting from the use cases Apple covered in Discover Observation in SwiftUI, there are many more nuanced and advanced cases that will require making some decisions on what’s best for your code. We plan to support some of those cases in the future, but for now we hope this is a nice place to start when adopting the new @Observable macro! Feel free to file feature requests or bugs.