{"id":117077,"date":"2020-03-24T14:12:34","date_gmt":"2020-03-24T14:12:34","guid":{"rendered":"https:\/\/developer.apple.com\/news\/?id=8vkqn3ih"},"modified":"2020-03-24T14:12:34","modified_gmt":"2020-03-24T14:12:34","slug":"how-to-debug-your-swiftui-previews-in-xcode","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2020\/03\/24\/how-to-debug-your-swiftui-previews-in-xcode\/","title":{"rendered":"How to debug your SwiftUI previews in Xcode"},"content":{"rendered":"<div class=\"inline-article-image\"><img decoding=\"async\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2020\/08\/how-to-debug-your-swiftui-previews-in-xcode.jpg\" data-hires=\"false\"><\/div>\n<p>With SwiftUI and Xcode 11, it\u2019s much faster to create great user interfaces for apps on iOS, macOS, watchOS, and tvOS. As you write your app, use Xcode\u2018s design tools at any point to see live previews of your app in different states and on different compatible devices \u2014 all without launching Simulator.<\/p>\n<p>And here\u2019s a valuable tip: We\u2019re going to break down how you can debug that SwiftUI code live in Xcode, too.<\/p>\n<h3>Enable Debug Preview in Xcode 11<\/h3>\n<p>When creating an interface for your app in SwiftUI, you\u2018ll see a preview inside Xcode that displays your app, formatted for your currently-selected device.<\/p>\n<p>If you\u2019re hitting an issue in your code, however, and don\u2019t know where to troubleshoot, you can instead enable Debug Preview to quickly find that pesky bug. Here\u2019s how to do it.<\/p>\n<ol>\n<li>Open your Swift project in Xcode 11.<\/li>\n<li>Right-click (or Control-click) on the Live Preview button in the bottom right corner of the preview.<\/li>\n<li>Select Debug Preview.<\/li>\n<\/ol>\n<div class=\"inline-article-image\" readability=\"34\"><img decoding=\"async\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2020\/08\/how-to-debug-your-swiftui-previews-in-xcode-1.jpg\" data-hires=\"false\"><\/p>\n<p class=\"typography-caption\">The Debug Preview mode in Xcode provides easy access to an assortment of debugging tools for your app, including a visual breakdown of your app\u2019s elements.<\/p>\n<\/div>\n<p>Now, you can troubleshoot your SwiftUI project using all of the usual debugging tools, such as breakpoints, view debugging, memory graph debugging, and logging to the Console.<\/p>\n<h3>Resources<\/h3>\n<p><a href=\"https:\/\/developer.apple.com\/xcode\/swiftui\/\">Learn more <span class=\"icon icon-after icon-chevronright nowrap\">about SwiftUI<\/span><\/a><\/p>\n<p><a href=\"https:\/\/developer.apple.com\/tutorials\/swiftui\/\">Check out Apple\u2019s <span class=\"icon icon-after icon-chevronright nowrap\">SwiftUI Tutorials<\/span><\/a><\/p>\n<p><a href=\"https:\/\/developer.apple.com\/wwdc19\/233\">Check out Mastering <span class=\"icon icon-after icon-chevronright nowrap\">SwiftUI Previews<\/span><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>With SwiftUI and Xcode 11, it\u2019s much faster to create great user interfaces for apps on iOS, macOS, watchOS, and tvOS. As you write your app, use Xcode\u2018s design tools at any point to see live previews of your app in different states and on different compatible devices \u2014 all without launching Simulator. And here\u2019s [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":117078,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[],"class_list":["post-117077","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apple-developer-news"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/117077","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=117077"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/117077\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media\/117078"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=117077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=117077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=117077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}