GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

SOLVED: TabView: freeze when switching (randomly, but often)

Forums > SwiftUI

Hi everyone, my best wishes for this year to the swiftUI community, One of my views inside the TabView randomly freeze sometimes when navigate in the app and when i switch from a tab to an other. It is random, but make the tabView unusable for me (every button on the view become like disabled and doesn't work anymore). I feel like as soon as the views start to get a bit too complex, the tabView doesn't follow behind ... Maybe that it is a bug in SwiftUI (someone seems to have the same problem in apple dev forum https://developer.apple.com/forums/thread/124475). Has anyone else seen this as well ? I'm thinking about making my own tabView...

3      

I have not had this problem with TabView

You could try putting the TabView in the ....App.swift eg (This is the way Apple seem to do it)

@main
struct TestApp: App {
    var body: some Scene {
        WindowGroup {
            TabView {
                ContentOneView()
                    .tabItem {
                        Image(systemName: "1.square")
                    }

                ContentTwoView()
                    .tabItem {
                        Image(systemName: "2.square")
                    }
            }
        }
    }
}

or if still get it can you refactor the screen that "freezes" which may help.

3      

Hi @NigelGee, thank you for your feedback. i will try to put all in the app.swift, (if i can do it neatly, because i have all the login/registration views to handle, but if it works...).

3      

Problem solved !

I started by putting everything in app.swift, but the problem persisted so I refactored the view and in fact the culprit seemed to be a computed property. Thanks for putting me on the right path 👍

4      

Hacking with Swift is sponsored by Alex.

SPONSORED Alex is the iOS & Mac developer’s ultimate AI assistant. It integrates with Xcode, offering a best-in-class Swift coding agent. Generate modern SwiftUI from images. Fast-apply suggestions from Claude 3.5 Sonnet, o3-mini, and DeepSeek R1. Autofix Swift 6 errors and warnings. And so much more. Start your 7-day free trial today!

Try for free!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.