SwiftUI TabView lifecycle is weird

I tested the life cycle of TabView and its sub-Views through the demo and found something strange. Please help analyze it. Thank you.

The demo project is here https://feedbackassistant.apple.com/feedback/15629780

Operation steps:

  • Step 1: launch app
  • Step 2: click Login button

the below log is correct

  • SettingsViewModel init
  • HomeViewModel init
  • HomeView appear

Step 3: click Settings tab

  • SettingsView appear (correct)

Step 4: click Refresh TabView button the below log is incorrect

  • Refresh TabView
  • StatusViewModel init
  • AccountViewModel init
  • StatusViewModel init (weird)
  • AccountViewModel init (weird)
  • HomeView appear (weird)
  • StatusViewModel deinit
  • AccountViewModel deinit
  • AccountView appear
  • SettingsViewModel deinit
  • HomeViewModel deinit

Expect log:

  • Refresh TabView
  • SettingsViewModel deinit
  • HomeViewModel deinit
  • StatusViewModel init
  • AccountViewModel init
  • AccountView appear
SwiftUI TabView lifecycle is weird
 
 
Q