Saturday, November 21, 2026
HomeiOS DevelopmentXcode 14 “Publishing adjustments from inside view updates just isn't allowed, this...

Xcode 14 “Publishing adjustments from inside view updates just isn’t allowed, this can trigger undefined conduct” – Donny Wals

[ad_1]

Revealed on: September 7, 2022

Expensive reader, for those who’ve discovered this web page you are in all probability encountering the error from the put up title. Let me begin by saying this put up does not give you a fast repair. As an alternative, it serves to indicate you the occasion the place I bumped into this difficulty in Xcode 14, and why I consider this difficulty is a bug and never an precise difficulty. I’ve final examined this with Xcode 14.0’s Launch Candidate. I’ve filed suggestions with Apple, the suggestions quantity is FB11278036 in case you wish to duplicate my difficulty.

A number of the SwiftUI code that I have been utilizing fantastic for a very long time now has just lately began arising with this purple warning.

Xcode 14 “Publishing adjustments from inside view updates just isn’t allowed, this can trigger undefined conduct” – Donny Wals

Initially I believed that there was an opportunity that I used to be, in reality, doing one thing bizarre all alongside and I began chipping away at my challenge till I had one thing that was sufficiently small to solely cowl a couple of strains, however nonetheless complicated sufficient to signify the true world.

In my case, the difficulty occurred with the next code:

class SampleObject: ObservableObject {
    @Revealed var publishedProp = 1337

    func mutate() {
        publishedProp = Int.random(in: 0...50)
    }
}

struct CellView: View {
    @ObservedObject var dataSource: SampleObject

    var physique: some View {
        VStack {
            Button(motion: {
                dataSource.mutate()
            }, label: {
                Textual content("Replace property")
            })

            Textual content("(dataSource.publishedProp)")
        }
    }
}

struct ContentView: View {
    @StateObject var dataSource = SampleObject()

    var physique: some View {
        Record {
            CellView(dataSource: dataSource)
        }
    }
}

This code actually does nothing outrageous or bizarre. A faucet on a button will merely mutate an @Revealed property, and I anticipate the listing to replace. Nothing fancy. Nonetheless, this code nonetheless throws up the purple warning. Compiling this similar challenge in Xcode 13.4.1 works fantastic, and older Xcode 14 betas additionally do not complain.

At this level, it looks as if this could be a bug in Record particularly as a result of altering the listing to a VStack or LazyVStack in a ScrollView doesn’t give me the identical warning. This tells me that there’s nothing essentially mistaken with the setup above.

One other factor that appears to work round this warning is to vary the kind of button that triggers the motion. For instance, utilizing a bordered button as proven beneath additionally runs with out the warning:

Button(motion: {
    dataSource.mutate()
}, label: {
    Textual content("Replace property")
}).buttonStyle(.bordered)

Or if you would like your button to appear like the default button model on iOS, you should utilize borderless:

Button(motion: {
    dataSource.mutate()
}, label: {
    Textual content("Replace property")
}).buttonStyle(.borderless)

It type of seems like something besides a default Button in a Record is okay.

For these causes, I sadly can’t offer you a correct repair for this difficulty. The issues I discussed are all workarounds IMO as a result of the unique code ought to work. All I can say is please file a suggestions ticket with Apple so we will hopefully get this mounted, documented, or in any other case defined. I will be requesting a code stage assist ticket from Apple to see if an Apple engineer may also help me determine this out.

As soon as I’ve a greater image of precisely what’s taking place I’ll replace this put up.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments