{"id":19690950,"url":"https://github.com/insidegui/macpreviewutils","last_synced_at":"2025-05-10T22:52:50.889Z","repository":{"id":65094338,"uuid":"581899807","full_name":"insidegui/MacPreviewUtils","owner":"insidegui","description":"Handy tools for SwiftUI previews on macOS.","archived":false,"fork":false,"pushed_at":"2024-04-15T17:33:14.000Z","size":4086,"stargazers_count":197,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-05-10T22:52:44.684Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/insidegui.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"insidegui"}},"created_at":"2022-12-24T19:33:25.000Z","updated_at":"2025-05-01T13:46:15.000Z","dependencies_parsed_at":"2024-04-15T18:56:36.124Z","dependency_job_id":null,"html_url":"https://github.com/insidegui/MacPreviewUtils","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"3d52597e5b6b65698b96e037539d2058c4668815"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insidegui%2FMacPreviewUtils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insidegui%2FMacPreviewUtils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insidegui%2FMacPreviewUtils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insidegui%2FMacPreviewUtils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/insidegui","download_url":"https://codeload.github.com/insidegui/MacPreviewUtils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253492615,"owners_count":21916964,"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":[],"created_at":"2024-11-11T19:07:27.434Z","updated_at":"2025-05-10T22:52:50.870Z","avatar_url":"https://github.com/insidegui.png","language":"Swift","readme":"# MacPreviewUtils\n\nThis package includes a few tools that I use all the time when developing macOS apps, whether using SwiftUI or AppKit.\nThese tools help make SwiftUI previews more useful for Mac app developers.\n\n## Translucency Fix\n\nBy default, `Material` and other views that rely on an app being active in order to render properly won't look right in SwiftUI previews,\nmaking it difficult to iterate on detailed designs that use such effects.\n\nJust by linking against the MacPreviewUtils library, you'll get an automatic fix for translucency in SwiftUI previews.\n\n### Example:\n\nNo code needed, just link your app target (or one of the targets it links against) to MacPreviewUtils.\n\n![Material preview](./images/Materials.png)\n\n## Am I a SwiftUI Preview?\n\nThe library includes a couple of extensions on `ProcessInfo` that can be used at runtime to check whether the process\nis running in a SwiftUI preview. This should be used sparingly, but it can be extremely useful to adapt certain app behaviors\nthat can be problematic when running in SwiftUI previews.\n\n\n### Example:\n\n```swift\nfunc doSomethingThatBreaksSwiftUIPreviews() {\n    guard !ProcessInfo.isSwiftUIPreview else { return }\n    \n    // ...\n}\n```\n\n## Pin SwiftUI Preview to a Specific Display\n\nSometimes you might want to be looking at your SwiftUI preview in an external display, such as an iPad connected via Sidecar.\nThis library includes a modifier that can do just that.\n\n### Example:\n\n```swift\nstruct MyView_Previews: PreviewProvider {\n    static var previews: some View {\n        /// This preview will show up on the connected Sidecar display.\n        MyView()\n            .pin(to: .sidecarDisplay, alignment: .center, options: [.interactiveOnly])\n    }\n}\n```\n\n## Debug Previews Using `print()`\n\nBreakpoints are great for debugging an app while it's running, and sometimes `print()` statements may also be a good way to debug certain values over time.\nUnfortunately, while running in Xcode previews, there's no easy way to view your app's standard output, unless you're using `OSLog`/`NSLog` and filtering in the Console app.\n\nThis library includes a modifier that displays a little console window while running an Xcode preview, allowing you to debug your previews using `print` statements.\n\nThe `previewConsole()` may also be combined with the `pin(to:)` modifier mentioned above, in which case it'll follow the display and position selection from that modifier.\n\n```swift\nstruct MyView_Previews: PreviewProvider {\n    static var previews: some View {\n        MyView()\n            .previewConsole()\n    }\n}\n```\n\n\u003e Note: this modifier will only show the app's standard output, so it won't display messages logged with `os_log` or `Logger`. Support for the unified logging system and stderr is planned.\n\n![Preview Console Demo](./images/PreviewConsole.jpg) \n\n## Will this mess up my app when debugging or in production?\n\nNope!\n\nMost of the code in this library is in `#if DEBUG`/`#endif` statements, so it won't even be included\nin release builds of the app.\n\nThe modifiers included are designed for use only in SwiftUI previews, so you should not use them\ndirectly on view implementations. However, they all check if the code is running in a SwiftUI preview\nbefore doing anything, so that regular debug builds are not affected.\n\nBe sure to include `#if DEBUG`/`#endif` around your SwiftUI previews that\nuse this library as well, in order to prevent compiler errors when building for release.\n","funding_links":["https://github.com/sponsors/insidegui"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finsidegui%2Fmacpreviewutils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finsidegui%2Fmacpreviewutils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finsidegui%2Fmacpreviewutils/lists"}