Using the .task view modifier

The .onAppear view modifier allows you to execute costly initialization only when a view becomes visible. The .task view modifier allows breaking out asynchronous initialization.