Creating an Observable class in an Xcode playground seems to cause an error. This stops me from being able to run the playground.
As a demo, try creating a playground page and add:
import Foundation
import Observation // Doesn't seem to make a difference whether it's added or not.
@Observable public class NewViewModel: Observable {
var value: Int = 1
func increment() {
value += 1
}
}
Tapping the run button logs the following error (and then it builds successfully, buy fails silently):
error: Untitled Page.xcplaygroundpage:7:9: error: expansion of macro 'ObservationTracked()' did not produce a non-observing accessor
var value: Int = 1
^
Putting the cursor on @Observable
and then selecting Editor > Expand Macro shows that value
has been annotated with @ObservationTracked
and I if I re-run the playground I can even see the @ObservationTracked generated code.
Macros:
import Foundation
import Observation // Doesn't seem to make a difference whether it's added or not.
@Observable public class NewViewModel: Observable {
@ObservationTracked
// original-source-range: /Users/gabriel.banfalvi/work/forums_observation/ObservationFramework.playground/Pages/Untitled Page.xcplaygroundpage:7:5-7:5
var value: Int = 1
{
@storageRestrictions(initializes: _value)
init(initialValue) {
_value = initialValue
}
get {
access(keyPath: \.value)
return _value
}
set {
withMutation(keyPath: \.value) {
_value = newValue
}
}
}
// original-source-range: /Users/gabriel.banfalvi/work/forums_observation/ObservationFramework.playground/Pages/Untitled Page.xcplaygroundpage:7:20-7:23
func increment() {
value += 1
}
@ObservationIgnored private let _$observationRegistrar = Observation.ObservationRegistrar()
internal nonisolated func access<Member>(
keyPath: KeyPath<NewViewModel, Member>
) {
_$observationRegistrar.access(self, keyPath: keyPath)
}
internal nonisolated func withMutation<Member, MutationResult>(
keyPath: KeyPath<NewViewModel, Member>,
_ mutation: () throws -> MutationResult
) rethrows -> MutationResult {
try _$observationRegistrar.withMutation(of: self, keyPath: keyPath, mutation)
}
@ObservationIgnored private var _value: Int = 1
// original-source-range: /Users/gabriel.banfalvi/work/forums_observation/ObservationFramework.playground/Pages/Untitled Page.xcplaygroundpage:12:1-12:1
}
I can't seem to be able to expand the @ObservationIgnored
macros, which may or may not be related to the issue. I can't expand them in a regular Xcode app, but it doesn't lead to any problems there.
Im running an iOS playground. I get this in Xcodes 15 beta 6 and 5. I get a different error in earlier versions.
Still broken in beta 7