{"id":13995063,"url":"https://github.com/ole/swiftui-view-lifecycle","last_synced_at":"2025-04-07T06:06:27.774Z","repository":{"id":64460532,"uuid":"575515384","full_name":"ole/swiftui-view-lifecycle","owner":"ole","description":"Observe how different SwiftUI container views affect state and lifecycle events (onAppear, onDisappear).","archived":false,"fork":false,"pushed_at":"2023-03-18T15:10:12.000Z","size":3628,"stargazers_count":387,"open_issues_count":2,"forks_count":19,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-31T04:07:00.362Z","etag":null,"topics":["swiftui"],"latest_commit_sha":null,"homepage":"https://oleb.net/2022/swiftui-view-lifecycle/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ole.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-12-07T17:25:40.000Z","updated_at":"2025-03-17T10:19:17.000Z","dependencies_parsed_at":"2024-01-18T05:35:49.110Z","dependency_job_id":null,"html_url":"https://github.com/ole/swiftui-view-lifecycle","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ole%2Fswiftui-view-lifecycle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ole%2Fswiftui-view-lifecycle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ole%2Fswiftui-view-lifecycle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ole%2Fswiftui-view-lifecycle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ole","download_url":"https://codeload.github.com/ole/swiftui-view-lifecycle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247601447,"owners_count":20964864,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["swiftui"],"created_at":"2024-08-09T14:03:14.019Z","updated_at":"2025-04-07T06:06:27.737Z","avatar_url":"https://github.com/ole.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"#  SwiftUI View Lifecycle\n\nAn iOS and macOS app that demonstrates how different SwiftUI constructs and SwiftUI container views affect:\n\n- the lifetime of `@State`\n- the firing of events such as `onAppear` and `onDisappear`\n\nBy [Ole Begemann](https://oleb.net), 2022\n\n[SwiftUI View Lifecycle app on GitHub](https://github.com/ole/swiftui-view-lifecycle\u003e)\u003cbr\u003e\nMy article introducing the app: [Understanding View Lifecycles (2022-12-15)](https://oleb.net/2022/swiftui-view-lifecycle/)\n\n## Usage\n\n1. Open the project in Xcode.\n2. Run the app on the iOS simulator, an iOS device, or on macOS.\n3. Click through the list of examples and observe the timestamps when certain lifecycle events happened.\n\n## Requirements\n\nRequires iOS 16 or macOS 13.\n\n## Screenshots\n\n### iPhone\n\n\u003cimg src=\"assets/ios-collage.png\" width=\"692\" height=\"339\"/\u003e\n\n### iPad\n\n\u003cimg src=\"assets/ipad-tabview.png\" width=\"658\" height=\"477\"/\u003e\n\n### Mac\n\n\u003cimg src=\"assets/mac-list-dynamic.png\" width=\"749\" height=\"525\"/\u003e\n\n## The `LifecycleMonitor` view\n\nAll examples use one or more [`LifecycleMonitor`](https://github.com/ole/swiftui-view-lifecycle/blob/main/ViewLifecycle/LifecycleMonitor.swift) views as their content. The view below tracks its lifecycle events and displays them as constantly-updating timestamps. For example, this view got created 1:26 minutes ago, which is also when its `@State` got created. Its `.onAppear` and `.onDisappear` actions were last called 15 and 47 seconds ago, respectively:\n\n\u003cimg src=\"assets/LifecycleMonitor-example.png\" width=\"331\" height=\"123\"/\u003e\n\nAs you interact with the app, e.g. by scrolling through a `List`, you’ll see these timestamps update (or not, depending on the container view). Pay special attention to resets of the `@State` field because this means that the view got destroyed and recreated, losing all of its internal state.\n\nThe view’s background color is set to a random color when its `@State` is created, so color changes are another indication that the view identity has changed.\n\n## License\n\n[MIT license](LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fole%2Fswiftui-view-lifecycle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fole%2Fswiftui-view-lifecycle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fole%2Fswiftui-view-lifecycle/lists"}