{"appState":{"pageLoadApiCallsStatus":true},"categoryState":{"relatedCategories":{"headers":{"timestamp":"2022-08-15T12:31:09+00:00"},"categoryId":33512,"data":{"title":"Technology","slug":"technology","image":{"src":"https://www.dummies.com/wp-content/uploads/technology-category.jpg","width":643,"height":1286},"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512}],"parentCategory":{"categoryId":0,"title":null,"slug":null,"_links":null},"childCategories":[{"categoryId":33513,"title":"Computers","slug":"computers","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33513"},"image":{"src":"/img/background-image-2.fabfbd5c.png","width":0,"height":0}},{"categoryId":33537,"title":"Cybersecurity","slug":"cybersecurity","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33537"},"image":{"src":"/img/background-image-1.daf74cf0.png","width":0,"height":0}},{"categoryId":33538,"title":"Digital Audio & Radio","slug":"digital-audio-radio","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33538"},"image":{"src":"/img/background-image-2.fabfbd5c.png","width":0,"height":0}},{"categoryId":33543,"title":"Electronics","slug":"electronics","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33543"},"image":{"src":"/img/background-image-1.daf74cf0.png","width":0,"height":0}},{"categoryId":33572,"title":"Information Technology","slug":"information-technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33572"},"image":{"src":"/img/background-image-2.fabfbd5c.png","width":0,"height":0}},{"categoryId":33587,"title":"Internet Basics","slug":"internet-basics","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33587"},"image":{"src":"/img/background-image-1.daf74cf0.png","width":0,"height":0}},{"categoryId":33588,"title":"Notable Websites","slug":"notable-websites","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33588"},"image":{"src":"/img/background-image-2.fabfbd5c.png","width":0,"height":0}},{"categoryId":33592,"title":"Programming & Web Design","slug":"programming-web-design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"image":{"src":"/img/background-image-1.daf74cf0.png","width":0,"height":0}},{"categoryId":33611,"title":"Social Media","slug":"social-media","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33611"},"image":{"src":"/img/background-image-2.fabfbd5c.png","width":0,"height":0}},{"categoryId":33618,"title":"Software","slug":"software","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33618"},"image":{"src":"/img/background-image-1.daf74cf0.png","width":0,"height":0}}],"description":"Technology. It makes the world go 'round. And whether you're a self-confessed techie or a total newbie, you'll find something to love among our hundreds of technology articles and books.","relatedArticles":{"self":"https://dummies-api.dummies.com/v2/articles?category=33512&offset=0&size=5"},"hasArticle":true,"hasBook":true},"_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"}},"relatedCategoriesLoadedStatus":"success"},"listState":{"list":{"count":10,"total":9369,"items":[{"headers":{"creationTime":"2022-08-12T16:27:48+00:00","modifiedTime":"2022-08-12T16:36:43+00:00","timestamp":"2022-08-12T18:01:08+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Software","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33618"},"slug":"software","categoryId":33618},{"name":"Microsoft Products","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33642"},"slug":"microsoft-products","categoryId":33642},{"name":"General Microsoft","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33652"},"slug":"general-microsoft","categoryId":33652}],"title":"Windows 365 For Dummies Cheat Sheet","strippedTitle":"windows 365 for dummies cheat sheet","slug":"windows-365-for-dummies-cheat-sheet","canonicalUrl":"","seo":{"metaDescription":"Learn what cloud computing with Windows 365 is all about, including how you sign up for a subscription and connect to your cloud PC.","noIndex":0,"noFollow":0},"content":"Windows 365 is Microsoft’s cloud-based operating system that lets you connect to your PC from anywhere in the world with an Internet connection. All you need is a physical device that you can use as a window into your cloud PC and you are good to go.\r\n\r\nGetting your head around using a PC in the cloud can take some time. It reminds us of the first time we saw the movie <em>The Matrix</em>. In other words, it can be a bit of a mind trip. You are using a physical computer, and then connecting to your cloud PC, and then using your physical computer just like it <em>is</em> your cloud PC. But your cloud PC lives and runs in the cloud, and your physical computer, any physical computer, is just something real you use to connect to your cloud PC and get work done.\r\n\r\nLike we said, it can take some time to get your head around it.","description":"Windows 365 is Microsoft’s cloud-based operating system that lets you connect to your PC from anywhere in the world with an Internet connection. All you need is a physical device that you can use as a window into your cloud PC and you are good to go.\r\n\r\nGetting your head around using a PC in the cloud can take some time. It reminds us of the first time we saw the movie <em>The Matrix</em>. In other words, it can be a bit of a mind trip. You are using a physical computer, and then connecting to your cloud PC, and then using your physical computer just like it <em>is</em> your cloud PC. But your cloud PC lives and runs in the cloud, and your physical computer, any physical computer, is just something real you use to connect to your cloud PC and get work done.\r\n\r\nLike we said, it can take some time to get your head around it.","blurb":"","authors":[{"authorId":9718,"name":"Ken Withee","slug":"ken-withee","description":" <p><b>Rosemarie Withee</b> is the president of Portal Integrators and founder of Scrum Now. Rosemarie is the author of <i>Microsoft Teams For Dummies</i> and other Dummies titles. </p> <p><b>Ken Withee</b> works for Microsoft and is part of the Azure team. Previously, he was a SharePoint consultant, and he has authored several books on Microsoft products. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/9718"}},{"authorId":10888,"name":"Rosemarie Withee","slug":"rosemarie-withee","description":" <p><b>Rosemarie Withee</b> is the president of Portal Integrators and founder of Scrum Now. Rosemarie is the author of <i>Microsoft Teams For Dummies</i> and other Dummies titles. </p> <p><b>Ken Withee</b> works for Microsoft and is part of the Azure team. Previously, he was a SharePoint consultant, and he has authored several books on Microsoft products. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/10888"}}],"primaryCategoryTaxonomy":{"categoryId":33652,"title":"General Microsoft","slug":"general-microsoft","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33652"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":null,"inThisArticle":[],"relatedArticles":{"fromBook":[],"fromCategory":[{"articleId":291623,"title":"Office 2021 For Macs For Dummies Cheat Sheet","slug":"office-2021-for-macs-for-dummies-cheat-sheet","categoryList":["technology","software","microsoft-products","general-microsoft"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/291623"}},{"articleId":290233,"title":"Microsoft 365 For Dummies Cheat Sheet","slug":"microsoft-365-for-dummies-cheat-sheet","categoryList":["technology","software","microsoft-products","general-microsoft"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/290233"}},{"articleId":290196,"title":"Office 2021 All-in-One For Dummies Cheat Sheet","slug":"office-2021-all-in-one-for-dummies-cheat-sheet","categoryList":["technology","software","microsoft-products","general-microsoft"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/290196"}},{"articleId":289688,"title":"Office 2021 For Seniors For Dummies Cheat Sheet","slug":"office-2021-for-seniors-for-dummies-cheat-sheet","categoryList":["technology","software","microsoft-products","general-microsoft"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/289688"}},{"articleId":265320,"title":"How to Create Charts in Office 365","slug":"how-to-create-charts-in-office-365","categoryList":["technology","software","microsoft-products","general-microsoft"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/265320"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":294446,"slug":"windows-365-for-dummies","isbn":"9781119880516","categoryList":["technology","software","microsoft-products","general-microsoft"],"amazon":{"default":"https://www.amazon.com/gp/product/1119880513/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119880513/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119880513-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119880513/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119880513/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":null,"width":0,"height":0},"title":"Windows 365 For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><p><b><b data-author-id=\"10888\">Rosemarie Withee</b></b> is the president of Portal Integrators and founder of Scrum Now. Rosemarie is the author of <i>Microsoft Teams For Dummies</i> and other Dummies titles. </p> <p><b>Ken Withee</b> works for Microsoft and is part of the Azure team. Previously, he was a SharePoint consultant, and he has authored several books on Microsoft products. <p><b>Rosemarie Withee</b> is the president of Portal Integrators and founder of Scrum Now. Rosemarie is the author of <i>Microsoft Teams For Dummies</i> and other Dummies titles. </p> <p><b><b data-author-id=\"9718\">Ken Withee</b></b> works for Microsoft and is part of the Azure team. Previously, he was a SharePoint consultant, and he has authored several books on Microsoft products.</p>","authors":[{"authorId":10888,"name":"Rosemarie Withee","slug":"rosemarie-withee","description":" <p><b>Rosemarie Withee</b> is the president of Portal Integrators and founder of Scrum Now. Rosemarie is the author of <i>Microsoft Teams For Dummies</i> and other Dummies titles. </p> <p><b>Ken Withee</b> works for Microsoft and is part of the Azure team. Previously, he was a SharePoint consultant, and he has authored several books on Microsoft products. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/10888"}},{"authorId":9718,"name":"Ken Withee","slug":"ken-withee","description":" <p><b>Rosemarie Withee</b> is the president of Portal Integrators and founder of Scrum Now. Rosemarie is the author of <i>Microsoft Teams For Dummies</i> and other Dummies titles. </p> <p><b>Ken Withee</b> works for Microsoft and is part of the Azure team. Previously, he was a SharePoint consultant, and he has authored several books on Microsoft products. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/9718"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;software&quot;,&quot;microsoft-products&quot;,&quot;general-microsoft&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119880516&quot;]}]\" id=\"du-slot-62f69564bf9e2\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;software&quot;,&quot;microsoft-products&quot;,&quot;general-microsoft&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119880516&quot;]}]\" id=\"du-slot-62f69564c01d4\"></div></div>"},"articleType":{"articleType":"Cheat Sheet","articleList":[{"articleId":0,"title":"","slug":null,"categoryList":[],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/"}}],"content":[{"title":"Getting started with Windows 365","thumb":null,"image":null,"content":"<p>Microsoft has moved the PC into the cloud with Windows 365. You can use almost any physical computer, even a phone or tablet, to connect to your cloud PC in order to get work done. When you are done working, just disconnect and your cloud PC stays put in the exact same state you left it. Your cloud PC waits until you connect to it again, from whichever physical device you choose to use at the time, and you start working again.</p>\n<p>To get started, you need a Microsoft 365 subscription. If you don’t already have one, then you can sign up for a new one on the Microsoft website at <a href=\"http://www.office.com\" target=\"_blank\" rel=\"noopener\">www.office.com</a>. Why is Microsoft 365 located at office.com? Because Microsoft 365 is a new name for Office 365 and Office 365 is the cloud version of Microsoft Office. Makes sense? Good!</p>\n<p>With your subscription ready to go, you sign up for Windows 365 by pointing your web browser to <a href=\"http://www.windows365.com\" target=\"_blank\" rel=\"noopener\">www.windows365.com</a>. On the site, select the type of cloud PC you want and assign the cloud PC to one of the users in your organization.</p>\n<p>The last step is to connect to your cloud PC and begin using it. You can connect using your web browser or a special client called Windows 365 Remote Desktop. After you’re connected, your cloud PC runs in a window and looks like a regular PC you might have on your desk. When you maximize the window, you get the feeling the physical computer you are typing on is actually your cloud PC.</p>\n<p>It isn’t, though! Your physical computer is just a way to connect to your cloud PC. After this concept becomes clear, it is easy to float between many different physical computers while always connecting and using your cloud PC. Your cloud PC becomes detached from the real world and any physical computer will do to connect to it and use it.</p>\n"},{"title":"Figuring out Windows 365 requirements","thumb":null,"image":null,"content":"<p>There are very few requirements to using Windows 365. The first, and most important, is that you must have a fairly fast Internet connection. The second is that you must have a physical device that you can use to connect to your cloud PC and use it. We recommend something with a full keyboard like a laptop or desktop computer. However, even a phone or tablet can be used in a pinch.</p>\n<p>As for the Windows 365 Remote Desktop client, it can be installed on a Windows computer, a Mac computer, an iPhone, iPad, Android phone, or Android tablet. If your physical computer is running Linux, then you can use the web browser. We are hoping for a full-fledged client for Linux soon, too!</p>\n"},{"title":"Learning Windows 365 terminology","thumb":null,"image":null,"content":"<p>Moving a PC into the cloud presents some real mind-bender scenarios. First, how can something like a PC move into the cloud? Where does it exist? Who turns it on? Is there a ghost floating in the cloud, too, who presses the keys on the PC?</p>\n<p>Well, your cloud PC actually lives in a Microsoft data center somewhere in the world. There are real computers in those data centers, and your cloud PC runs on those.</p>\n<p>Of course, every cloud PC doesn’t have its very own real PC in a data center. Instead, Microsoft runs technology to create virtual environments. Your cloud PC is actually a virtual computer and Microsoft maintains some super-powerful computers that handle all the details of connecting your virtual computer to the actual computer it is running on top of.</p>\n<p>Here are some definitions to help sort through the concept:</p>\n<ul>\n<li><strong>Cloud PC: </strong>A virtual computer running in a Microsoft data center that you connect to and use over the Internet.</li>\n<li><strong>Physical device: </strong>The laptop, desktop, phone, or tablet that you physically have in your hands and use to connect to the Internet so you can connect to your cloud PC.</li>\n<li><strong>Data center: </strong>A giant building that Microsoft owns where massive rows of computers reside. Microsoft uses these computers to provide all their services. All these computers are networked together. You might hear this referred to as <em>the Microsoft Cloud</em>. Really, it is just Microsoft’s network, though.</li>\n<li><strong>Microsoft 365: </strong>A marketing name for a bundle of services that Microsoft offers. The bundle was previously referred to as Office 365.</li>\n<li><strong>Office 365: </strong>The cloud version of the traditional Microsoft Office software products. Microsoft changed the name to Microsoft 365, although you will still see frequent references to Office 365.</li>\n<li><strong>Operating systems: </strong>A physical computer isn’t much more than a paperweight or doorstop without software to make it function. The software designed to make computers do stuff is called an <em>operating system</em>. With a cloud PC, the physical components of the computer are virtual, but the operating system performs the same function.</li>\n</ul>\n"},{"title":"Common apps in Windows 365","thumb":null,"image":null,"content":"<p>With Windows 365, you must have a Microsoft 365 subscription. These subscriptions come in many different flavors, and each includes different features and offerings. For example, if you want to install Microsoft Office on your cloud PC, then you want to make sure your Microsoft 365 subscription includes this option.</p>\n<p>In addition to Office, many other apps are available with Microsoft 365 and on your cloud PC. On your cloud PC, you will find traditional apps you find on a regular Windows computer, such as the Media Player, Voice Recorder, Notepad, and Calculator. You can also install just about any software you can imagine from the Windows Store on your cloud PC.</p>\n<p>Some of the new cloud-based apps that come with Microsoft 365 include: To-Do, Lists, Bookings, Whiteboard, and Stream. And of course, the most popular and powerful Microsoft 365 apps include SharePoint, OneDrive, and Teams.</p>\n"}],"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"Two years","lifeExpectancySetFrom":"2022-08-12T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":294664},{"headers":{"creationTime":"2016-03-26T14:02:54+00:00","modifiedTime":"2022-08-11T20:10:42+00:00","timestamp":"2022-08-12T00:01:04+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"HTML5","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33601"},"slug":"html5","categoryId":33601}],"title":"How to Create Definition Lists in HTML5","strippedTitle":"how to create definition lists in html5","slug":"how-to-create-definition-lists-in-html5","canonicalUrl":"","seo":{"metaDescription":"Definition lists group terms and definitions into a single list. Learn how to create definition lists in HTML5.","noIndex":0,"noFollow":0},"content":"Lists are powerful tools for grouping similar elements, and lists give visitors to your site an easy way to zoom in on groups of information. Just about anything fits in a list, from sets of instructions to collections of links. <i>Definition lists</i> group terms and definitions into a single list and require three elements to complete the list:\r\n<ul class=\"level-one\">\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"><dl></span>: Holds the list definitions (dl = definition list)</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"><dt></span>: Defines a term in the list (dt = definition term)</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"><dd></span>: Defines a definition for a term (dd = definition list definition)</p>\r\n</li>\r\n</ul>\r\nYou can have as many terms (defined by <span class=\"code\"><dt></span>) in a list (<span class=\"code\"><dl></span>) as you need. Each term can have one or more definitions (defined by <span class=\"code\"><dd></span>).\r\n\r\nCreating a definition list with two items requires tags and content in the following order:\r\n<ol class=\"level-one\">\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"><dl></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"><dt></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">First term name</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"></dt></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"><dd></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Content for the definition of the first item</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"></dd></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"><dt></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Second term name</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"></dt></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"><dd></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Content for the definition of the second item</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"></dd></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"></dl></span></p>\r\n</li>\r\n</ol>\r\nThe following definition list includes three terms, one of which has two definitions:\r\n<pre class=\"code\"><!DOCTYPE html>\r\n<html>\r\n <head>\r\n <meta charset=\"UTF-8\" />\r\n <title>Definition Lists</title>\r\n </head>\r\n <body>\r\n <h1>Markup Language Definitions</h1>\r\n <dl>\r\n <dt>SGML</dt>\r\n <dd>The Standard Generalized Markup Language</dd>\r\n <dt>HTML</dt>\r\n <dd>The Hypertext Markup Language</dd>\r\n <dd>The markup language you use to create web pages.</dd>\r\n <dt>XML</dt>\r\n <dd>The Extensible Markup Language</dd>\r\n </dl>\r\n </body>\r\n</html></pre>\r\nThe figure shows how a browser displays this HTML.\r\n\r\n<img src=\"https://www.dummies.com/wp-content/uploads/398569.image0.jpg\" alt=\"image0.jpg\" width=\"503\" height=\"400\" />\r\n<p class=\"Tip\">If you think items in a list are too close together, you can use CSS styles to carefully control all aspects of list appearance.</p>\r\nNote that definition lists often display differently inside different browsers, and they aren’t always handled the same by search engines or text-to-speech translators. About.com has a nice discussion of definition lists on their <a href=\"http://webdesign.about.com/od/htmltags/a/aa112006.htm\">Web Design / HTML page</a>.\r\n\r\nAlas, this means that definition lists may not be the best choice of formatting for lists you create (even lists of definitions). For a more detailed discussion, see the excellent coverage of this topic on <a href=\"http://www.maxdesign.com.au/articles/definition/\">Max Design</a>.","description":"Lists are powerful tools for grouping similar elements, and lists give visitors to your site an easy way to zoom in on groups of information. Just about anything fits in a list, from sets of instructions to collections of links. <i>Definition lists</i> group terms and definitions into a single list and require three elements to complete the list:\r\n<ul class=\"level-one\">\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"><dl></span>: Holds the list definitions (dl = definition list)</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"><dt></span>: Defines a term in the list (dt = definition term)</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"><dd></span>: Defines a definition for a term (dd = definition list definition)</p>\r\n</li>\r\n</ul>\r\nYou can have as many terms (defined by <span class=\"code\"><dt></span>) in a list (<span class=\"code\"><dl></span>) as you need. Each term can have one or more definitions (defined by <span class=\"code\"><dd></span>).\r\n\r\nCreating a definition list with two items requires tags and content in the following order:\r\n<ol class=\"level-one\">\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"><dl></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"><dt></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">First term name</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"></dt></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"><dd></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Content for the definition of the first item</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"></dd></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"><dt></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Second term name</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"></dt></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"><dd></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\">Content for the definition of the second item</p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"></dd></span></p>\r\n</li>\r\n \t<li>\r\n<p class=\"first-para\"><span class=\"code\"></dl></span></p>\r\n</li>\r\n</ol>\r\nThe following definition list includes three terms, one of which has two definitions:\r\n<pre class=\"code\"><!DOCTYPE html>\r\n<html>\r\n <head>\r\n <meta charset=\"UTF-8\" />\r\n <title>Definition Lists</title>\r\n </head>\r\n <body>\r\n <h1>Markup Language Definitions</h1>\r\n <dl>\r\n <dt>SGML</dt>\r\n <dd>The Standard Generalized Markup Language</dd>\r\n <dt>HTML</dt>\r\n <dd>The Hypertext Markup Language</dd>\r\n <dd>The markup language you use to create web pages.</dd>\r\n <dt>XML</dt>\r\n <dd>The Extensible Markup Language</dd>\r\n </dl>\r\n </body>\r\n</html></pre>\r\nThe figure shows how a browser displays this HTML.\r\n\r\n<img src=\"https://www.dummies.com/wp-content/uploads/398569.image0.jpg\" alt=\"image0.jpg\" width=\"503\" height=\"400\" />\r\n<p class=\"Tip\">If you think items in a list are too close together, you can use CSS styles to carefully control all aspects of list appearance.</p>\r\nNote that definition lists often display differently inside different browsers, and they aren’t always handled the same by search engines or text-to-speech translators. About.com has a nice discussion of definition lists on their <a href=\"http://webdesign.about.com/od/htmltags/a/aa112006.htm\">Web Design / HTML page</a>.\r\n\r\nAlas, this means that definition lists may not be the best choice of formatting for lists you create (even lists of definitions). For a more detailed discussion, see the excellent coverage of this topic on <a href=\"http://www.maxdesign.com.au/articles/definition/\">Max Design</a>.","blurb":"","authors":[{"authorId":9135,"name":"Ed Tittel","slug":"ed-tittel","description":" <p><b>Ed Tittel</b> is a 30&#45;year veteran of the technology industry with more than 140 computing books to his credit, including the bestselling <i>HTML For Dummies</i>. <p><b>Chris Minnick</b> runs Minnick Web Services. He teaches, speaks, and consults on web&#45;related topics and has contributed to numerous books, including <i>WebKit For Dummies</i>. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/9135"}},{"authorId":9070,"name":"Chris Minnick","slug":"chris-minnick","description":" <p>This All-in-One includes work by expert coders and coding educators, including <b>Chris Minnick and Eva Holland </b>coauthors of<i> Coding with JavaScript For Dummies</i>; <b>Nikhil Abraham,</b> author of <i>Coding For Dummies</i> and <i>Getting a Coding Job For Dummies;</i> <b>John Paul Mueller and Luca Massaron,</b> coauthors of <i>Python for Data Science For Dummies</i> and <i>Machine Learning For Dummies;</i> and <b>Barry Burd,</b> author of<i> Flutter For Dummies.</i></p> ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/9070"}}],"primaryCategoryTaxonomy":{"categoryId":33601,"title":"HTML5","slug":"html5","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33601"}},"secondaryCategoryTaxonomy":{"categoryId":34324,"title":"CSS3","slug":"css3","_links":{"self":"https://dummies-api.dummies.com/v2/categories/34324"}},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":null,"inThisArticle":[],"relatedArticles":{"fromBook":[{"articleId":207867,"title":"Beginning HTML5 & CSS3 For Dummies Cheat Sheet","slug":"beginning-html5-css3-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","html5"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/207867"}},{"articleId":204301,"title":"10 Stellar Web Resources for HTML5 and CSS3","slug":"10-stellar-web-resources-for-html5-and-css3","categoryList":["technology","programming-web-design","html5"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/204301"}},{"articleId":163221,"title":"CSS Property Reference","slug":"css-property-reference","categoryList":["technology","programming-web-design","html5"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/163221"}},{"articleId":163220,"title":"Know Your Elements!","slug":"know-your-elements","categoryList":["technology","programming-web-design","html5"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/163220"}},{"articleId":163158,"title":"Named Colors and Hex Values in HTML","slug":"named-colors-and-hex-values-in-html","categoryList":["technology","programming-web-design","html5"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/163158"}}],"fromCategory":[{"articleId":207867,"title":"Beginning HTML5 & CSS3 For Dummies Cheat Sheet","slug":"beginning-html5-css3-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","html5"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/207867"}},{"articleId":207816,"title":"HTML5 & CSS3 For Dummies Cheat Sheet","slug":"html5-css3-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","html5"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/207816"}},{"articleId":207788,"title":"HTML5 and CSS3 All-in-One For Dummies Cheat Sheet","slug":"html5-and-css3-all-in-one-for-dummies-cheat-sheet","categoryList":["technology","programming-web-design","html5"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/207788"}},{"articleId":204537,"title":"How to Create a New JavaScript File in Komodo Edit","slug":"how-to-create-a-new-javascript-file-in-komodo-edit","categoryList":["technology","programming-web-design","html5"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/204537"}},{"articleId":204532,"title":"How to Create Cascading Style Sheets (CSS) Simply and Easily","slug":"how-to-create-cascading-style-sheets-css-simply-and-easily","categoryList":["technology","programming-web-design","html5"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/204532"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281635,"slug":"beginning-html5-and-css3-for-dummies","isbn":"9781118657201","categoryList":["technology","programming-web-design","html5"],"amazon":{"default":"https://www.amazon.com/gp/product/1118657209/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1118657209/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1118657209-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1118657209/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1118657209/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/beginning-html5-and-css3-for-dummies-cover-9781118657201-205x255.jpg","width":205,"height":255},"title":"Beginning HTML5 and CSS3 For Dummies","testBankPinActivationLink":"","bookOutOfPrint":false,"authorsInfo":"<p><b data-author-id=\"9135\">Ed Tittel</b> is a 30-year veteran of the technology industry with more than 140 computing books to his credit, including the bestselling <i>HTML For Dummies</i>. </p>\n<p><b data-author-id=\"9070\">Chris Minnick</b> runs Minnick Web Services. He teaches, speaks, and consults on web-related topics and has contributed to numerous books, including <i>WebKit For Dummies</i>. </p>","authors":[{"authorId":9135,"name":"Ed Tittel","slug":"ed-tittel","description":" <p><b>Ed Tittel</b> is a 30&#45;year veteran of the technology industry with more than 140 computing books to his credit, including the bestselling <i>HTML For Dummies</i>. <p><b>Chris Minnick</b> runs Minnick Web Services. He teaches, speaks, and consults on web&#45;related topics and has contributed to numerous books, including <i>WebKit For Dummies</i>. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/9135"}},{"authorId":9070,"name":"Chris Minnick","slug":"chris-minnick","description":" <p>This All-in-One includes work by expert coders and coding educators, including <b>Chris Minnick and Eva Holland </b>coauthors of<i> Coding with JavaScript For Dummies</i>; <b>Nikhil Abraham,</b> author of <i>Coding For Dummies</i> and <i>Getting a Coding Job For Dummies;</i> <b>John Paul Mueller and Luca Massaron,</b> coauthors of <i>Python for Data Science For Dummies</i> and <i>Machine Learning For Dummies;</i> and <b>Barry Burd,</b> author of<i> Flutter For Dummies.</i></p> ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/9070"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;html5&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781118657201&quot;]}]\" id=\"du-slot-62f59840b90eb\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;html5&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781118657201&quot;]}]\" id=\"du-slot-62f59840b9933\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"Two years","lifeExpectancySetFrom":"2022-08-11T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":161044},{"headers":{"creationTime":"2020-10-28T17:58:33+00:00","modifiedTime":"2022-08-10T16:49:12+00:00","timestamp":"2022-08-10T18:01:05+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"App Development","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33594"},"slug":"app-development","categoryId":33594}],"title":"9 SwiftUI Tips and Tricks","strippedTitle":"9 swiftui tips and tricks","slug":"9-swiftui-tips-and-tricks","canonicalUrl":"","seo":{"metaDescription":"Want to improve your SwiftUI skills? We've got you covered! Give these nine tips and tricks a try to level up your developing.","noIndex":0,"noFollow":0},"content":"<a href=\"https://www.dummies.com/programming/macintosh/a-brief-primer-on-swift-programming-basic-syntax/\" target=\"_blank\" rel=\"noopener\">SwiftUI</a> makes creating your iOS applications easy and efficient. However, there are neat tricks that are not so obvious. Here, you learn some of these tips and tricks so that you can become a better SwiftUI developer.\r\n<h2 id=\"tab1\" ><a name=\"_Toc37583247\"></a>Resume SwiftUI’s live preview</h2>\r\nMy number-one pet peeve about SwiftUI is that the live preview feature in <a href=\"https://www.dummies.com/web-design-development/mobile-apps/using-xcode-to-develop-an-app/\" target=\"_blank\" rel=\"noopener\">Xcode</a> doesn’t always work. Very often, changes made to your code will cause the automatic previewing feature to pause. Even though your code is perfectly correct and there is no error, the live preview just can’t seem to update automatically.\r\n\r\nOf course, you could click the Resume button to update the preview, but you waste precious time moving your mouse to click the button.\r\n<p class=\"article-tips tip\">A better way is to press ⌘+Option+P. This causes the live preview to resume and update itself. Now that you know this trick, there is no reason to click the Resume button anymore!</p>\r\nYou may also want to check out the <a href=\"https://developer.apple.com/library/archive/documentation/IDEs/Conceptual/xcode_help-command_shortcuts/MenuCommands/MenuCommands014.html.\" target=\"_blank\" rel=\"noopener\">list of shortcuts for working in Xcode</a>.\r\n<h2 id=\"tab2\" ><a name=\"_Toc37583249\"></a>Combine text views in SwiftUI</h2>\r\nHere is a neat little trick that you should know if you want to display the various words in a sentence in different colors and sizes. Instead of using the <code>HStack</code> view to group various <code>Text</code> views together, you can simply use the plus (<strong>+</strong>) operator to add different <code>Text</code> views together, like this:\r\n<pre class=\"code\">struct ContentView: View {\r\n var body: some View {\r\n Text(\"Red \")\r\n .foregroundColor(.red)\r\n .font(.largeTitle)\r\n +\r\n Text(\"Green \")\r\n .foregroundColor(.green)\r\n .font(.body)\r\n +\r\n Text(\"Blue\")\r\n .foregroundColor(.blue)\r\n .font(.title)\r\n }\r\n}</pre>\r\nHow cool is that? Here’s the output.\r\n\r\n[caption id=\"attachment_274193\" align=\"aligncenter\" width=\"125\"]<img class=\"wp-image-274193 size-medium\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-text-views-125x255.jpg\" alt=\"SwiftUI Text views\" width=\"125\" height=\"255\" /> Concatenating different Text views together.[/caption]\r\n\r\n \r\n\r\nIf you want all the texts to be of the same font size, group them together using a <code>Group</code> view and apply the <code>font()</code> modifier on the <code>Group</code> view:\r\n<pre class=\"code\">struct ContentView: View {\r\n \r\n var body: some View {\r\n Group {\r\n Text(\"Red \")\r\n .foregroundColor(.red)\r\n +\r\n Text(\"Green \")\r\n .foregroundColor(.green)\r\n +\r\n Text(\"Blue\")\r\n .foregroundColor(.blue)\r\n }\r\n .font(.largeTitle)\r\n }\r\n}</pre>\r\n<h2 id=\"tab3\" ><a name=\"_Toc37583250\"></a>Create custom modifiers in SwiftUI</h2>\r\nSwift modifiers allow you to change the behaviors of views. Consider the following example:\r\n<pre class=\"code\">import SwiftUI\r\n\r\nstruct ContentView: View {\r\n var body: some View {\r\n VStack {\r\n Text(\"Leonardo da Vinci\")\r\n .bold()\r\n .font(.largeTitle)\r\n .foregroundColor(.blue)\r\n .shadow(radius: 2)\r\n \r\n Text(\"Vincent van Gogh\")\r\n .bold()\r\n .font(.largeTitle)\r\n .foregroundColor(.blue)\r\n .shadow(radius: 2) \r\n }\r\n }\r\n}</pre>\r\nHere, you apply the same set of modifiers to the two <code>Text</code> views. You often do that when you want to ensure consistencies in your UI (for example, applying the same set of UI styles when displaying certain information in your application). Instead of repeating the same set of modifiers again and again, wouldn’t it be easier if you could just encapsulate all the modifiers into yet another modifier?\r\n\r\nWhat you can do it is create another struct that conforms to the <code>ViewModifier</code> protocol. This protocol requires you to implement a <code>body() </code>method that has a <code>Content </code>parameter. You then apply whatever modifiers you want to this <code>Content</code> argument and return it:\r\n<pre class=\"code\">import SwiftUI\r\n\r\nstruct Title: ViewModifier {\r\n func body(content: Content) -> some View {\r\n content\r\n .font(.largeTitle)\r\n .foregroundColor(.blue)\r\n .shadow(radius: 2)\r\n }\r\n}</pre>\r\nTo use the newly created <code>Title</code> struct on the <code>Text</code> view, apply the<code> modifier() </code>modifier and pass in the <code>Title</code> struct, like this:\r\n<pre class=\"code\">struct ContentView: View {\r\n var body: some View {\r\n VStack {\r\n Text(\"Leonardo da Vinci\")\r\n .bold()\r\n .modifier(Title())\r\n \r\n Text(\"Vincent van Gogh\")\r\n .bold()\r\n .modifier(Title())\r\n }\r\n }\r\n}</pre>\r\nTo make the <code>Title</code> struct look more like a true modifier, create an extension to the <code>View</code> protocol and give it a name — say,<code> titleStyle</code>:\r\n<pre class=\"code\">import SwiftUI\r\n\r\nextension View {\r\n func titleStyle() -> some View {\r\n self.modifier(Title())\r\n }\r\n}</pre>\r\nYou can now apply the <code>titleStyle()</code> modifier to the two<code> Text</code> views:\r\n<pre class=\"code\">struct ContentView: View {\r\n var body: some View {\r\n VStack {\r\n Text(\"Leonardo da Vinci\")\r\n .bold()\r\n .titleStyle()\r\n \r\n Text(\"Vincent van Gogh\")\r\n .bold()\r\n .titleStyle()\r\n }\r\n }\r\n}</pre>\r\n<h2 id=\"tab4\" ><a name=\"_Toc37583251\"></a>Display multiple alerts in SwiftUI</h2>\r\nUsually, in SwiftUI you apply a single <code>alert()</code> modifier to a single view. For example, when the user taps a button, you can display an alert by using the <code>alert()</code> modifier to the button. If you have multiple buttons, you can attach an <code>alert()</code> modifier to each button.\r\n\r\nHowever, there are times when you need to display multiple different alerts for a single view. Applying multiple <code>alert()</code> modifiers to a single view will not work correctly, because the last modifier will override the earlier ones. To solve this problem, you can use a single<code> alert()</code> modifier, and use a<code> switch </code>statement within the modifier to decide which alert to display.\r\n\r\nThe following example shows a button that, when it’s clicked, generates a random number of either 1 or 2 and uses it to decide which alert to display:\r\n<pre class=\"code\">struct ContentView: View {\r\n @State private var displayAlert = false\r\n @State private var alertToDisplay = 0\r\n \r\n var body: some View {\r\n Button(action: {\r\n self.alertToDisplay = Int.random(in: 1..<3)\r\n self.displayAlert = true\r\n }) {\r\n Text(\"Display Alert\")\r\n }\r\n .alert(isPresented: $displayAlert) {\r\n switch alertToDisplay {\r\n case 1:\r\n return Alert(title: Text(\"Alert 1\"),\r\n message: Text(\"This is Alert 1\"))\r\n default:\r\n return Alert(title: Text(\"Alert 2\"),\r\n message: Text(\"This is Alert 2\"))\r\n }\r\n }\r\n }\r\n}</pre>\r\n<h2 id=\"tab5\" ><a name=\"_Toc37583252\"></a>Enable debug preview in SwiftUI</h2>\r\nBy default, the preview canvas doesn’t display outputs printed using the <code>print()</code> function. This isn’t useful, however, because often you want to use the<code> print()</code> function as a quick debugging option. The good news is, you can easily fix this.\r\n\r\nIn the preview canvas, right-click the Play button and select Debug Preview.\r\n\r\n[caption id=\"attachment_274194\" align=\"aligncenter\" width=\"181\"]<img class=\"wp-image-274194 size-medium\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-debug-preview-181x255.jpg\" alt=\"SwiftUI debug preview\" width=\"181\" height=\"255\" /> Enabling the Debug Preview feature in the preview canvas.[/caption]\r\n\r\n \r\n\r\nNow if you tap the button, your code will print the output in the Output window:\r\n<pre class=\"code\">struct ContentView: View {\r\n var body: some View {\r\n Button (\"Tap Me\") {\r\n print(\"Button was tapped...\")\r\n }\r\n }\r\n}</pre>\r\nIf the Output window is not shown in Xcode, press ⌘+Shift+C and it should appear.\r\n<h2 id=\"tab6\" ><a name=\"_Toc37583253\"></a>Preview your SwiftUI app using different devices</h2>\r\nYou’re familiar with using the preview canvas to preview your app. By default, Xcode automatically picks an appropriate device based on your target.\r\n\r\n[caption id=\"attachment_274195\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-274195 size-full\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-target-set.jpg\" alt=\"SwiftUI target set\" width=\"556\" height=\"67\" /> The target set for your project (iPhone 11 Pro Max, in this example).[/caption]\r\n\r\n \r\n\r\nYou can preview your app on different modes — light mode and dark mode — using the <code>environment() </code>modifier:\r\n<pre class=\"code\">struct ContentView_Previews: PreviewProvider {\r\n static var previews: some View {\r\n Group {\r\n ContentView()\r\n .environment(\\.colorScheme, .light)\r\n ContentView()\r\n .environment(\\.colorScheme, .dark)\r\n }\r\n }\r\n}</pre>\r\nIn addition to previewing in different modes, you can alter the size of the preview window, allowing you to have a glimpse of how your UI will look under different screen dimensions. You can do so using the<code> previewLayout() </code>modifier:\r\n<pre class=\"code\">static var previews: some View {\r\n Group {\r\n ContentView()\r\n .environment(\\.colorScheme, .light)\r\n .previewLayout((.fixed(width: 400, \r\n height: 600)))\r\n ContentView()\r\n .environment(\\.colorScheme, .dark)\r\n }\r\n }</pre>\r\nThe image below shows the top preview displaying your UI in a dimension of 400 x 600 pixels. Note that clicking the Live Preview button will revert the preview back to the default size.\r\n\r\n[caption id=\"attachment_274196\" align=\"aligncenter\" width=\"197\"]<img class=\"wp-image-274196 size-large\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-preview-app-197x586.jpg\" alt=\"SwiftUI app preview\" width=\"197\" height=\"586\" /> Previewing your app in the specified dimensions.[/caption]\r\n\r\n \r\n\r\nIf you want to preview your UI on multiple devices, you can use a <code>ForEach</code> loop, supply a list of device names, and then use the<code> previewDevice()</code> modifier on the<code> ContentView</code>, like this:\r\n<pre class=\"code\"> static var previews: some View {\r\n ForEach([\"iPhone 11\", \"iPhone SE\"], \r\n id: \\.self) { deviceName in\r\n ContentView()\r\n .environment(\\.colorScheme, \r\n .light)\r\n .previewDevice(PreviewDevice(\r\n rawValue: deviceName))\r\n .previewDisplayName(deviceName)\r\n }\r\n }</pre>\r\nThe following image shows the preview on the iPhone 11 and the iPhone SE. Notice that you can display the name of the device using the <code>previewDisplayName()</code> modifier.\r\n\r\n[caption id=\"attachment_274197\" align=\"aligncenter\" width=\"174\"]<img class=\"wp-image-274197 size-large\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-app-preview-174x586.jpg\" alt=\"preview app in SwiftUI\" width=\"174\" height=\"586\" /> Previewing the app on an iPhone 11 and an iPhone SE.[/caption]\r\n\r\n \r\n\r\nCheck out the <a href=\"https://developer.apple.com/documentation/swiftui/list/3270295-previewdevice\" target=\"_blank\" rel=\"noopener\">full list of devices that you can preview</a>.\r\n<h2 id=\"tab7\" ><a name=\"_Toc37583254\"></a>Dark mode only works on NavigationView</h2>\r\nAs stated, you can use the environment() modifier to set the preview to dark mode so that you can see how your UI will look like in dark mode.\r\n\r\nHowever, it seems like the dark preview mode only works for the <code>NavigationView</code>. For example, consider the following example where you have two <code>Text</code> views contained within a <code>VStack </code>view:\r\n<pre class=\"code\">import SwiftUI\r\n\r\nstruct ContentView: View {\r\n var body: some View {\r\n VStack {\r\n Text(\"Leonardo da Vinci\")\r\n Text(\"Vincent van Gogh\")\r\n }\r\n }\r\n}</pre>\r\nSuppose you use the <code>environment()</code> modifier to set the preview mode to<code> dark</code>, like this:\r\n<pre class=\"code\">struct ContentView_Previews: PreviewProvider {\r\n static var previews: some View {\r\n ContentView()\r\n .environment(\\.colorScheme, .dark)\r\n }\r\n}</pre>\r\nThe words in the <code>Text</code> views automatically change to white, but the background remains white (running on the simulator or an actual device doesn’t have this issue), as shown below. So, essentially, you get a white screen.\r\n\r\n[caption id=\"attachment_274198\" align=\"aligncenter\" width=\"137\"]<img class=\"wp-image-274198 size-medium\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-dark-mode-137x255.jpg\" alt=\"SwiftUI dark mode\" width=\"137\" height=\"255\" /> Previewing in dark mode but the background of the app is still white.[/caption]\r\n\r\n \r\n\r\nTo fix this problem, wrap the <code>ContentView</code> view using a <code>ZStack</code> and set its background to black, like this:\r\n<pre class=\"code\">struct ContentView_Previews: PreviewProvider {\r\n static var previews: some View {\r\n ZStack {\r\n Color(.black)\r\n ContentView()\r\n }\r\n .edgesIgnoringSafeArea(.all)\r\n .environment(\\.colorScheme, .dark)\r\n }\r\n}</pre>\r\nThe image below shows the text showing up on a black background.\r\n\r\n[caption id=\"attachment_274199\" align=\"aligncenter\" width=\"138\"]<img class=\"wp-image-274199 size-medium\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-app-dark-mode-138x255.jpg\" alt=\"SwiftUI dark mode\" width=\"138\" height=\"255\" /> You can now preview the dark mode correctly.[/caption]\r\n\r\n \r\n<h2 id=\"tab8\" ><a name=\"_Toc37583256\"></a>Extract subviews in SwiftUI</h2>\r\nYour UI may contain quite a large number of views. This is very common if you have a complicated UI. However, you can simplify your UI by extracting some of the views as subviews. Consider the following example:\r\n<pre class=\"code\">import SwiftUI\r\n\r\nstruct ContentView: View {\r\n var body: some View {\r\n HStack {\r\n Image(\"weimenglee\")\r\n .resizable()\r\n .frame(width: CGFloat(120),\r\n height: CGFloat(120))\r\n .cornerRadius(CGFloat(15),\r\n antialiased: true)\r\n VStack {\r\n Text(\"Wei-Meng Lee\")\r\n .font(.largeTitle)\r\n .bold()\r\n Text(\"Founder\")\r\n Text(\"Developer Learning Solutions\")\r\n .italic()\r\n Text(\"http://calendar.learn2develop.net\")\r\n Text(\"@weimenglee\")\r\n }\r\n }\r\n }\r\n}</pre>\r\nTo break down the UI into smaller subviews so that your UI is more modular and manageable, follow these steps:\r\n<ol>\r\n \t<li>In the preview canvas, select the <code>Image</code> view and press the ⌘ key.\r\n\r\n[caption id=\"attachment_274200\" align=\"aligncenter\" width=\"247\"]<img class=\"wp-image-274200 size-medium\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-subviews-247x255.jpg\" alt=\"SwiftUI subviews\" width=\"247\" height=\"255\" /> Extracting views as subviews in the preview canvas.[/caption]</li>\r\n \t<li>Select Extract Subview.</li>\r\n \t<li>Name the new view PhotoView.</li>\r\n</ol>\r\n[caption id=\"attachment_274201\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-274201 size-full\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-name-subview.jpg\" alt=\"name subview SwiftUI\" width=\"556\" height=\"373\" /> Naming the newly extracted subview.[/caption]\r\n\r\n \r\n\r\nThe<code> Image</code> view will now be extracted as a new struct named PhotoView:\r\n<pre class=\"code\">struct ContentView: View {\r\n var body: some View {\r\n HStack {\r\n PhotoView()\r\n VStack {\r\n Text(\"Wei-Meng Lee\")\r\n .font(.largeTitle)\r\n .bold()\r\n Text(\"Founder\")\r\n Text(\"Developer Learning Solutions\")\r\n .italic()\r\n Text(\"http://calendar.learn2develop.net\")\r\n Text(\"@weimenglee\")\r\n }\r\n }\r\n }\r\n}\r\n\r\nstruct PhotoView: View {\r\n var body: some View {\r\n Image(\"weimenglee\")\r\n .resizable()\r\n .frame(width: CGFloat(120),\r\n height: CGFloat(120))\r\n .cornerRadius(CGFloat(15),\r\n antialiased: true)\r\n }\r\n}</pre>\r\nYou can now also extract the<code> VStack</code> and save it as another struct named <code>DetailsView</code>. Now your UI looks like the following, which is more maintainable:\r\n<pre class=\"code\">struct ContentView: View {\r\n var body: some View {\r\n HStack {\r\n PhotoView()\r\n DetailsView()\r\n }\r\n }\r\n}\r\n\r\nstruct PhotoView: View {\r\n...\r\n}\r\n\r\nstruct DetailsView: View {\r\n var body: some View {\r\n VStack {\r\n Text(\"Wei-Meng Lee\")\r\n .font(.largeTitle)\r\n .bold()\r\n Text(\"Founder\")\r\n Text(\"Developer Learning Solutions\")\r\n .italic()\r\n Text(\"http://calendar.learn2develop.net\")\r\n Text(\"@weimenglee\")\r\n }\r\n }\r\n}</pre>\r\n<h2 id=\"tab9\" ><a name=\"_Toc37583257\"></a>Display a context menu in SwiftUI</h2>\r\nOne of the innovative features of iPhone is the support for Haptic Touch (which replaces the 3D Touch on older iPhones). Using Haptic Touch, you can long-press an item on your iPhone and a context-sensitive menu appears (if the app you’re using supports it). You can support this feature in SwiftUI as well.\r\n\r\nTo attach a context menu to a view, use the<code> contextMenu()</code> modifier:\r\n\r\nTo attach a context menu to a view, use the contextMenu() modifier:\r\n<pre class=\"code\">struct ContentView: View {\r\n var body: some View {\r\n Image(\"Mac Pro\")\r\n .resizable()\r\n .frame(width: 300, height: 280)\r\n .contextMenu {\r\n Button(action: {\r\n print(\"Save Image button tapped...\")\r\n }) {\r\n Text(\"Save Image\")\r\n Image(systemName: \r\n \"tray.and.arrow.down\")\r\n }\r\n Button(action: {\r\n print(\"Add to Cart button tapped...\")\r\n }) {\r\n Text(\"Add to Cart\")\r\n Image(systemName: \"plus\")\r\n }\r\n }\r\n }\r\n}</pre>\r\nTo create a context menu, you provide a list of<code> Button</code> views, and the content of each button is automatically wrapped using an <code>HStack</code> view. Now when you long-press the <code>Image</code> view, a context menu appears.\r\n\r\n[caption id=\"attachment_274202\" align=\"aligncenter\" width=\"244\"]<img class=\"wp-image-274202 size-medium\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-image-view-244x255.jpg\" alt=\"SwiftUI Image view\" width=\"244\" height=\"255\" /> Implementing a context menu on an Image view.[/caption]\r\n\r\n \r\n\r\nWant to learn more? Check out our <a href=\"https://www.dummies.com/programming/macintosh/swift/swiftui-for-dummies-cheat-sheet/\" target=\"_blank\" rel=\"noopener\">SwifUI Cheat Sheet</a>.","description":"<a href=\"https://www.dummies.com/programming/macintosh/a-brief-primer-on-swift-programming-basic-syntax/\" target=\"_blank\" rel=\"noopener\">SwiftUI</a> makes creating your iOS applications easy and efficient. However, there are neat tricks that are not so obvious. Here, you learn some of these tips and tricks so that you can become a better SwiftUI developer.\r\n<h2 id=\"tab1\" ><a name=\"_Toc37583247\"></a>Resume SwiftUI’s live preview</h2>\r\nMy number-one pet peeve about SwiftUI is that the live preview feature in <a href=\"https://www.dummies.com/web-design-development/mobile-apps/using-xcode-to-develop-an-app/\" target=\"_blank\" rel=\"noopener\">Xcode</a> doesn’t always work. Very often, changes made to your code will cause the automatic previewing feature to pause. Even though your code is perfectly correct and there is no error, the live preview just can’t seem to update automatically.\r\n\r\nOf course, you could click the Resume button to update the preview, but you waste precious time moving your mouse to click the button.\r\n<p class=\"article-tips tip\">A better way is to press ⌘+Option+P. This causes the live preview to resume and update itself. Now that you know this trick, there is no reason to click the Resume button anymore!</p>\r\nYou may also want to check out the <a href=\"https://developer.apple.com/library/archive/documentation/IDEs/Conceptual/xcode_help-command_shortcuts/MenuCommands/MenuCommands014.html.\" target=\"_blank\" rel=\"noopener\">list of shortcuts for working in Xcode</a>.\r\n<h2 id=\"tab2\" ><a name=\"_Toc37583249\"></a>Combine text views in SwiftUI</h2>\r\nHere is a neat little trick that you should know if you want to display the various words in a sentence in different colors and sizes. Instead of using the <code>HStack</code> view to group various <code>Text</code> views together, you can simply use the plus (<strong>+</strong>) operator to add different <code>Text</code> views together, like this:\r\n<pre class=\"code\">struct ContentView: View {\r\n var body: some View {\r\n Text(\"Red \")\r\n .foregroundColor(.red)\r\n .font(.largeTitle)\r\n +\r\n Text(\"Green \")\r\n .foregroundColor(.green)\r\n .font(.body)\r\n +\r\n Text(\"Blue\")\r\n .foregroundColor(.blue)\r\n .font(.title)\r\n }\r\n}</pre>\r\nHow cool is that? Here’s the output.\r\n\r\n[caption id=\"attachment_274193\" align=\"aligncenter\" width=\"125\"]<img class=\"wp-image-274193 size-medium\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-text-views-125x255.jpg\" alt=\"SwiftUI Text views\" width=\"125\" height=\"255\" /> Concatenating different Text views together.[/caption]\r\n\r\n \r\n\r\nIf you want all the texts to be of the same font size, group them together using a <code>Group</code> view and apply the <code>font()</code> modifier on the <code>Group</code> view:\r\n<pre class=\"code\">struct ContentView: View {\r\n \r\n var body: some View {\r\n Group {\r\n Text(\"Red \")\r\n .foregroundColor(.red)\r\n +\r\n Text(\"Green \")\r\n .foregroundColor(.green)\r\n +\r\n Text(\"Blue\")\r\n .foregroundColor(.blue)\r\n }\r\n .font(.largeTitle)\r\n }\r\n}</pre>\r\n<h2 id=\"tab3\" ><a name=\"_Toc37583250\"></a>Create custom modifiers in SwiftUI</h2>\r\nSwift modifiers allow you to change the behaviors of views. Consider the following example:\r\n<pre class=\"code\">import SwiftUI\r\n\r\nstruct ContentView: View {\r\n var body: some View {\r\n VStack {\r\n Text(\"Leonardo da Vinci\")\r\n .bold()\r\n .font(.largeTitle)\r\n .foregroundColor(.blue)\r\n .shadow(radius: 2)\r\n \r\n Text(\"Vincent van Gogh\")\r\n .bold()\r\n .font(.largeTitle)\r\n .foregroundColor(.blue)\r\n .shadow(radius: 2) \r\n }\r\n }\r\n}</pre>\r\nHere, you apply the same set of modifiers to the two <code>Text</code> views. You often do that when you want to ensure consistencies in your UI (for example, applying the same set of UI styles when displaying certain information in your application). Instead of repeating the same set of modifiers again and again, wouldn’t it be easier if you could just encapsulate all the modifiers into yet another modifier?\r\n\r\nWhat you can do it is create another struct that conforms to the <code>ViewModifier</code> protocol. This protocol requires you to implement a <code>body() </code>method that has a <code>Content </code>parameter. You then apply whatever modifiers you want to this <code>Content</code> argument and return it:\r\n<pre class=\"code\">import SwiftUI\r\n\r\nstruct Title: ViewModifier {\r\n func body(content: Content) -> some View {\r\n content\r\n .font(.largeTitle)\r\n .foregroundColor(.blue)\r\n .shadow(radius: 2)\r\n }\r\n}</pre>\r\nTo use the newly created <code>Title</code> struct on the <code>Text</code> view, apply the<code> modifier() </code>modifier and pass in the <code>Title</code> struct, like this:\r\n<pre class=\"code\">struct ContentView: View {\r\n var body: some View {\r\n VStack {\r\n Text(\"Leonardo da Vinci\")\r\n .bold()\r\n .modifier(Title())\r\n \r\n Text(\"Vincent van Gogh\")\r\n .bold()\r\n .modifier(Title())\r\n }\r\n }\r\n}</pre>\r\nTo make the <code>Title</code> struct look more like a true modifier, create an extension to the <code>View</code> protocol and give it a name — say,<code> titleStyle</code>:\r\n<pre class=\"code\">import SwiftUI\r\n\r\nextension View {\r\n func titleStyle() -> some View {\r\n self.modifier(Title())\r\n }\r\n}</pre>\r\nYou can now apply the <code>titleStyle()</code> modifier to the two<code> Text</code> views:\r\n<pre class=\"code\">struct ContentView: View {\r\n var body: some View {\r\n VStack {\r\n Text(\"Leonardo da Vinci\")\r\n .bold()\r\n .titleStyle()\r\n \r\n Text(\"Vincent van Gogh\")\r\n .bold()\r\n .titleStyle()\r\n }\r\n }\r\n}</pre>\r\n<h2 id=\"tab4\" ><a name=\"_Toc37583251\"></a>Display multiple alerts in SwiftUI</h2>\r\nUsually, in SwiftUI you apply a single <code>alert()</code> modifier to a single view. For example, when the user taps a button, you can display an alert by using the <code>alert()</code> modifier to the button. If you have multiple buttons, you can attach an <code>alert()</code> modifier to each button.\r\n\r\nHowever, there are times when you need to display multiple different alerts for a single view. Applying multiple <code>alert()</code> modifiers to a single view will not work correctly, because the last modifier will override the earlier ones. To solve this problem, you can use a single<code> alert()</code> modifier, and use a<code> switch </code>statement within the modifier to decide which alert to display.\r\n\r\nThe following example shows a button that, when it’s clicked, generates a random number of either 1 or 2 and uses it to decide which alert to display:\r\n<pre class=\"code\">struct ContentView: View {\r\n @State private var displayAlert = false\r\n @State private var alertToDisplay = 0\r\n \r\n var body: some View {\r\n Button(action: {\r\n self.alertToDisplay = Int.random(in: 1..<3)\r\n self.displayAlert = true\r\n }) {\r\n Text(\"Display Alert\")\r\n }\r\n .alert(isPresented: $displayAlert) {\r\n switch alertToDisplay {\r\n case 1:\r\n return Alert(title: Text(\"Alert 1\"),\r\n message: Text(\"This is Alert 1\"))\r\n default:\r\n return Alert(title: Text(\"Alert 2\"),\r\n message: Text(\"This is Alert 2\"))\r\n }\r\n }\r\n }\r\n}</pre>\r\n<h2 id=\"tab5\" ><a name=\"_Toc37583252\"></a>Enable debug preview in SwiftUI</h2>\r\nBy default, the preview canvas doesn’t display outputs printed using the <code>print()</code> function. This isn’t useful, however, because often you want to use the<code> print()</code> function as a quick debugging option. The good news is, you can easily fix this.\r\n\r\nIn the preview canvas, right-click the Play button and select Debug Preview.\r\n\r\n[caption id=\"attachment_274194\" align=\"aligncenter\" width=\"181\"]<img class=\"wp-image-274194 size-medium\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-debug-preview-181x255.jpg\" alt=\"SwiftUI debug preview\" width=\"181\" height=\"255\" /> Enabling the Debug Preview feature in the preview canvas.[/caption]\r\n\r\n \r\n\r\nNow if you tap the button, your code will print the output in the Output window:\r\n<pre class=\"code\">struct ContentView: View {\r\n var body: some View {\r\n Button (\"Tap Me\") {\r\n print(\"Button was tapped...\")\r\n }\r\n }\r\n}</pre>\r\nIf the Output window is not shown in Xcode, press ⌘+Shift+C and it should appear.\r\n<h2 id=\"tab6\" ><a name=\"_Toc37583253\"></a>Preview your SwiftUI app using different devices</h2>\r\nYou’re familiar with using the preview canvas to preview your app. By default, Xcode automatically picks an appropriate device based on your target.\r\n\r\n[caption id=\"attachment_274195\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-274195 size-full\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-target-set.jpg\" alt=\"SwiftUI target set\" width=\"556\" height=\"67\" /> The target set for your project (iPhone 11 Pro Max, in this example).[/caption]\r\n\r\n \r\n\r\nYou can preview your app on different modes — light mode and dark mode — using the <code>environment() </code>modifier:\r\n<pre class=\"code\">struct ContentView_Previews: PreviewProvider {\r\n static var previews: some View {\r\n Group {\r\n ContentView()\r\n .environment(\\.colorScheme, .light)\r\n ContentView()\r\n .environment(\\.colorScheme, .dark)\r\n }\r\n }\r\n}</pre>\r\nIn addition to previewing in different modes, you can alter the size of the preview window, allowing you to have a glimpse of how your UI will look under different screen dimensions. You can do so using the<code> previewLayout() </code>modifier:\r\n<pre class=\"code\">static var previews: some View {\r\n Group {\r\n ContentView()\r\n .environment(\\.colorScheme, .light)\r\n .previewLayout((.fixed(width: 400, \r\n height: 600)))\r\n ContentView()\r\n .environment(\\.colorScheme, .dark)\r\n }\r\n }</pre>\r\nThe image below shows the top preview displaying your UI in a dimension of 400 x 600 pixels. Note that clicking the Live Preview button will revert the preview back to the default size.\r\n\r\n[caption id=\"attachment_274196\" align=\"aligncenter\" width=\"197\"]<img class=\"wp-image-274196 size-large\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-preview-app-197x586.jpg\" alt=\"SwiftUI app preview\" width=\"197\" height=\"586\" /> Previewing your app in the specified dimensions.[/caption]\r\n\r\n \r\n\r\nIf you want to preview your UI on multiple devices, you can use a <code>ForEach</code> loop, supply a list of device names, and then use the<code> previewDevice()</code> modifier on the<code> ContentView</code>, like this:\r\n<pre class=\"code\"> static var previews: some View {\r\n ForEach([\"iPhone 11\", \"iPhone SE\"], \r\n id: \\.self) { deviceName in\r\n ContentView()\r\n .environment(\\.colorScheme, \r\n .light)\r\n .previewDevice(PreviewDevice(\r\n rawValue: deviceName))\r\n .previewDisplayName(deviceName)\r\n }\r\n }</pre>\r\nThe following image shows the preview on the iPhone 11 and the iPhone SE. Notice that you can display the name of the device using the <code>previewDisplayName()</code> modifier.\r\n\r\n[caption id=\"attachment_274197\" align=\"aligncenter\" width=\"174\"]<img class=\"wp-image-274197 size-large\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-app-preview-174x586.jpg\" alt=\"preview app in SwiftUI\" width=\"174\" height=\"586\" /> Previewing the app on an iPhone 11 and an iPhone SE.[/caption]\r\n\r\n \r\n\r\nCheck out the <a href=\"https://developer.apple.com/documentation/swiftui/list/3270295-previewdevice\" target=\"_blank\" rel=\"noopener\">full list of devices that you can preview</a>.\r\n<h2 id=\"tab7\" ><a name=\"_Toc37583254\"></a>Dark mode only works on NavigationView</h2>\r\nAs stated, you can use the environment() modifier to set the preview to dark mode so that you can see how your UI will look like in dark mode.\r\n\r\nHowever, it seems like the dark preview mode only works for the <code>NavigationView</code>. For example, consider the following example where you have two <code>Text</code> views contained within a <code>VStack </code>view:\r\n<pre class=\"code\">import SwiftUI\r\n\r\nstruct ContentView: View {\r\n var body: some View {\r\n VStack {\r\n Text(\"Leonardo da Vinci\")\r\n Text(\"Vincent van Gogh\")\r\n }\r\n }\r\n}</pre>\r\nSuppose you use the <code>environment()</code> modifier to set the preview mode to<code> dark</code>, like this:\r\n<pre class=\"code\">struct ContentView_Previews: PreviewProvider {\r\n static var previews: some View {\r\n ContentView()\r\n .environment(\\.colorScheme, .dark)\r\n }\r\n}</pre>\r\nThe words in the <code>Text</code> views automatically change to white, but the background remains white (running on the simulator or an actual device doesn’t have this issue), as shown below. So, essentially, you get a white screen.\r\n\r\n[caption id=\"attachment_274198\" align=\"aligncenter\" width=\"137\"]<img class=\"wp-image-274198 size-medium\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-dark-mode-137x255.jpg\" alt=\"SwiftUI dark mode\" width=\"137\" height=\"255\" /> Previewing in dark mode but the background of the app is still white.[/caption]\r\n\r\n \r\n\r\nTo fix this problem, wrap the <code>ContentView</code> view using a <code>ZStack</code> and set its background to black, like this:\r\n<pre class=\"code\">struct ContentView_Previews: PreviewProvider {\r\n static var previews: some View {\r\n ZStack {\r\n Color(.black)\r\n ContentView()\r\n }\r\n .edgesIgnoringSafeArea(.all)\r\n .environment(\\.colorScheme, .dark)\r\n }\r\n}</pre>\r\nThe image below shows the text showing up on a black background.\r\n\r\n[caption id=\"attachment_274199\" align=\"aligncenter\" width=\"138\"]<img class=\"wp-image-274199 size-medium\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-app-dark-mode-138x255.jpg\" alt=\"SwiftUI dark mode\" width=\"138\" height=\"255\" /> You can now preview the dark mode correctly.[/caption]\r\n\r\n \r\n<h2 id=\"tab8\" ><a name=\"_Toc37583256\"></a>Extract subviews in SwiftUI</h2>\r\nYour UI may contain quite a large number of views. This is very common if you have a complicated UI. However, you can simplify your UI by extracting some of the views as subviews. Consider the following example:\r\n<pre class=\"code\">import SwiftUI\r\n\r\nstruct ContentView: View {\r\n var body: some View {\r\n HStack {\r\n Image(\"weimenglee\")\r\n .resizable()\r\n .frame(width: CGFloat(120),\r\n height: CGFloat(120))\r\n .cornerRadius(CGFloat(15),\r\n antialiased: true)\r\n VStack {\r\n Text(\"Wei-Meng Lee\")\r\n .font(.largeTitle)\r\n .bold()\r\n Text(\"Founder\")\r\n Text(\"Developer Learning Solutions\")\r\n .italic()\r\n Text(\"http://calendar.learn2develop.net\")\r\n Text(\"@weimenglee\")\r\n }\r\n }\r\n }\r\n}</pre>\r\nTo break down the UI into smaller subviews so that your UI is more modular and manageable, follow these steps:\r\n<ol>\r\n \t<li>In the preview canvas, select the <code>Image</code> view and press the ⌘ key.\r\n\r\n[caption id=\"attachment_274200\" align=\"aligncenter\" width=\"247\"]<img class=\"wp-image-274200 size-medium\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-subviews-247x255.jpg\" alt=\"SwiftUI subviews\" width=\"247\" height=\"255\" /> Extracting views as subviews in the preview canvas.[/caption]</li>\r\n \t<li>Select Extract Subview.</li>\r\n \t<li>Name the new view PhotoView.</li>\r\n</ol>\r\n[caption id=\"attachment_274201\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-274201 size-full\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-name-subview.jpg\" alt=\"name subview SwiftUI\" width=\"556\" height=\"373\" /> Naming the newly extracted subview.[/caption]\r\n\r\n \r\n\r\nThe<code> Image</code> view will now be extracted as a new struct named PhotoView:\r\n<pre class=\"code\">struct ContentView: View {\r\n var body: some View {\r\n HStack {\r\n PhotoView()\r\n VStack {\r\n Text(\"Wei-Meng Lee\")\r\n .font(.largeTitle)\r\n .bold()\r\n Text(\"Founder\")\r\n Text(\"Developer Learning Solutions\")\r\n .italic()\r\n Text(\"http://calendar.learn2develop.net\")\r\n Text(\"@weimenglee\")\r\n }\r\n }\r\n }\r\n}\r\n\r\nstruct PhotoView: View {\r\n var body: some View {\r\n Image(\"weimenglee\")\r\n .resizable()\r\n .frame(width: CGFloat(120),\r\n height: CGFloat(120))\r\n .cornerRadius(CGFloat(15),\r\n antialiased: true)\r\n }\r\n}</pre>\r\nYou can now also extract the<code> VStack</code> and save it as another struct named <code>DetailsView</code>. Now your UI looks like the following, which is more maintainable:\r\n<pre class=\"code\">struct ContentView: View {\r\n var body: some View {\r\n HStack {\r\n PhotoView()\r\n DetailsView()\r\n }\r\n }\r\n}\r\n\r\nstruct PhotoView: View {\r\n...\r\n}\r\n\r\nstruct DetailsView: View {\r\n var body: some View {\r\n VStack {\r\n Text(\"Wei-Meng Lee\")\r\n .font(.largeTitle)\r\n .bold()\r\n Text(\"Founder\")\r\n Text(\"Developer Learning Solutions\")\r\n .italic()\r\n Text(\"http://calendar.learn2develop.net\")\r\n Text(\"@weimenglee\")\r\n }\r\n }\r\n}</pre>\r\n<h2 id=\"tab9\" ><a name=\"_Toc37583257\"></a>Display a context menu in SwiftUI</h2>\r\nOne of the innovative features of iPhone is the support for Haptic Touch (which replaces the 3D Touch on older iPhones). Using Haptic Touch, you can long-press an item on your iPhone and a context-sensitive menu appears (if the app you’re using supports it). You can support this feature in SwiftUI as well.\r\n\r\nTo attach a context menu to a view, use the<code> contextMenu()</code> modifier:\r\n\r\nTo attach a context menu to a view, use the contextMenu() modifier:\r\n<pre class=\"code\">struct ContentView: View {\r\n var body: some View {\r\n Image(\"Mac Pro\")\r\n .resizable()\r\n .frame(width: 300, height: 280)\r\n .contextMenu {\r\n Button(action: {\r\n print(\"Save Image button tapped...\")\r\n }) {\r\n Text(\"Save Image\")\r\n Image(systemName: \r\n \"tray.and.arrow.down\")\r\n }\r\n Button(action: {\r\n print(\"Add to Cart button tapped...\")\r\n }) {\r\n Text(\"Add to Cart\")\r\n Image(systemName: \"plus\")\r\n }\r\n }\r\n }\r\n}</pre>\r\nTo create a context menu, you provide a list of<code> Button</code> views, and the content of each button is automatically wrapped using an <code>HStack</code> view. Now when you long-press the <code>Image</code> view, a context menu appears.\r\n\r\n[caption id=\"attachment_274202\" align=\"aligncenter\" width=\"244\"]<img class=\"wp-image-274202 size-medium\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-image-view-244x255.jpg\" alt=\"SwiftUI Image view\" width=\"244\" height=\"255\" /> Implementing a context menu on an Image view.[/caption]\r\n\r\n \r\n\r\nWant to learn more? Check out our <a href=\"https://www.dummies.com/programming/macintosh/swift/swiftui-for-dummies-cheat-sheet/\" target=\"_blank\" rel=\"noopener\">SwifUI Cheat Sheet</a>.","blurb":"","authors":[{"authorId":33413,"name":"Wei-Meng Lee","slug":"wei-meng-lee","description":" <p><b>Wei-Meng Lee</b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p> ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33413"}}],"primaryCategoryTaxonomy":{"categoryId":33594,"title":"App Development","slug":"app-development","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33594"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":null,"inThisArticle":[{"label":"Resume SwiftUI’s live preview","target":"#tab1"},{"label":"Combine text views in SwiftUI","target":"#tab2"},{"label":"Create custom modifiers in SwiftUI","target":"#tab3"},{"label":"Display multiple alerts in SwiftUI","target":"#tab4"},{"label":"Enable debug preview in SwiftUI","target":"#tab5"},{"label":"Preview your SwiftUI app using different devices","target":"#tab6"},{"label":"Dark mode only works on NavigationView","target":"#tab7"},{"label":"Extract subviews in SwiftUI","target":"#tab8"},{"label":"Display a context menu in SwiftUI","target":"#tab9"}],"relatedArticles":{"fromBook":[{"articleId":274241,"title":"How to Make Your Own Animation in SwiftUI","slug":"how-to-make-your-own-animation-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274241"}},{"articleId":274231,"title":"Understanding How to Animate in SwiftUI","slug":"understanding-how-to-animate-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274231"}},{"articleId":274224,"title":"How to Use UIKit in SwiftUI","slug":"how-to-use-uikit-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274224"}},{"articleId":274217,"title":"Swift Closures","slug":"swift-closures","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274217"}},{"articleId":274211,"title":"A Quick Intro to Swift Functions","slug":"a-quick-intro-to-swift-functions","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274211"}}],"fromCategory":[{"articleId":274241,"title":"How to Make Your Own Animation in SwiftUI","slug":"how-to-make-your-own-animation-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274241"}},{"articleId":274231,"title":"Understanding How to Animate in SwiftUI","slug":"understanding-how-to-animate-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274231"}},{"articleId":274224,"title":"How to Use UIKit in SwiftUI","slug":"how-to-use-uikit-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274224"}},{"articleId":274217,"title":"Swift Closures","slug":"swift-closures","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274217"}},{"articleId":274211,"title":"A Quick Intro to Swift Functions","slug":"a-quick-intro-to-swift-functions","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274211"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281877,"slug":"swiftui-for-dummies","isbn":"9781119652687","categoryList":["technology","programming-web-design","app-development"],"amazon":{"default":"https://www.amazon.com/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119652685-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/swiftui-for-dummies-cover-9781119652687-203x255.jpg","width":203,"height":255},"title":"SwiftUI For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b><b data-author-id=\"33413\">Wei-Meng Lee</b></b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p>","authors":[{"authorId":33413,"name":"Wei-Meng Lee","slug":"wei-meng-lee","description":" <p><b>Wei-Meng Lee</b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p> ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33413"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;app-development&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119652687&quot;]}]\" id=\"du-slot-62f3f261eda7f\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;app-development&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119652687&quot;]}]\" id=\"du-slot-62f3f261ee323\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"One year","lifeExpectancySetFrom":"2022-08-10T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":274192},{"headers":{"creationTime":"2020-10-06T19:16:21+00:00","modifiedTime":"2022-08-10T16:46:26+00:00","timestamp":"2022-08-10T18:01:05+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"App Development","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33594"},"slug":"app-development","categoryId":33594}],"title":"What Is Swift Programming? Understanding What SwiftUI Is","strippedTitle":"what is swift programming? understanding what swiftui is","slug":"what-is-swift-programming-understanding-what-swiftui-is","canonicalUrl":"","seo":{"metaDescription":"SwiftUI is a framework for developing apps for Apple products. Swift is the new programming language to help fill the gaps of UIKit. Find out more.","noIndex":0,"noFollow":0},"content":"SwiftUI is a declarative programming framework for developing UIs for <a href=\"https://www.dummies.com/web-design-development/ios/why-you-should-develop-ios-apps/\" target=\"_blank\" rel=\"noopener\">iOS</a>, iPadOS, watchOS, tvOS, and macOS applications. In fact, SwiftUI was invented by the watchOS group at Apple.\r\n\r\nBefore SwiftUI was introduced, most developers use UIKit and Storyboard (which is still supported by Apple in the current version of Xcode to design a UI. Using UIKit and Storyboard, developers drag and drop View controls onto View Controllers and connect them to outlets and actions on the View Controller classes. This model of building UIs is known as <em>Model View Controller</em> (MVC), which creates a clean separation between UI and business logic.\r\n\r\nThe following shows a simple implementation in UIKit and Storyboard. Here, a <code>Button</code> and <code>Label</code> view have been added to the View Controller in Storyboard; two outlets and an action have been created to connect to them:\r\n<pre class=\"code\">class ViewController: UIViewController {\r\n\r\n <strong> @IBOutlet weak var lbl: UILabel!\r\n @IBOutlet weak var button: UIButton!\r\n @IBAction func btnClicked(_ sender: Any) {\r\n lbl.text = \"Button tapped\"\r\n }</strong></pre>\r\nFor laying out the views, you use auto-layout to position the button and label in the middle of the screen (both horizontally and vertically).\r\n\r\nTo customize the look and feel of the button, you can code it in the <code>loadView()</code> method, like this:\r\n<pre class=\"code\"> override func loadView() {\r\n super.loadView()\r\n\r\n <strong>// background color\r\n button.backgroundColor = UIColor.yellow\r\n\r\n // button text and color\r\n button.setTitle(\"Submit\", for: .normal)\r\n button.setTitleColor(.black, for: .normal)\r\n\r\n // padding\r\n button.contentEdgeInsets = UIEdgeInsets(\r\n top: 10, left: 10, bottom: 10, right: 10)\r\n\r\n // border\r\n button.layer.borderColor =\r\n UIColor.darkGray.cgColor\r\n button.layer.borderWidth = 3.0\r\n\r\n // text font\r\n button.titleLabel!.font =\r\n UIFont.systemFont(ofSize: 26, weight:\r\n UIFont.Weight.regular)\r\n\r\n // rounder corners\r\n button.layer.cornerRadius = 10\r\n\r\n // auto adjust button size\r\n button.sizeToFit()\r\n </strong> }</pre>\r\nThe following image shows the button that has customized. UIKit is an <em>event-driven</em> framework, where you can reference each view in your view controller, update its appearance, or handle an event through <em>delegates</em> when some events occurred.\r\n\r\n[caption id=\"attachment_273770\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-273770 size-full\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-uikit.jpg\" alt=\"UIKit\" width=\"556\" height=\"563\" /> UIKit is event driven, and it uses delegates to handle events.[/caption]\r\n\r\n \r\n\r\nIn contrast, SwiftUI is a <em>state-driven, </em>declarative framework. In SwiftUI, you can implement all the above with the following statements:\r\n<pre class=\"code\">struct ContentView: View {\r\n <strong> @State private var label = \"label\"</strong>\r\n\r\n var body: some View {\r\n <strong>VStack {\r\n Button(action: {\r\n self.label = \"Button tapped\"\r\n }) {\r\n Text(\"Submit\")\r\n .padding(EdgeInsets(\r\n top: 10, leading: 10,\r\n bottom: 10, trailing: 10))\r\n .background(Color.yellow)\r\n .foregroundColor(Color.black)\r\n .border(Color.gray, width: 3)\r\n .font(Font.system(size: 26.0))\r\n .overlay(\r\n RoundedRectangle(cornerRadius: 10)\r\n .stroke(Color.gray,\r\n lineWidth: 5)\r\n </strong> <strong> )\r\n }\r\n Text(label)\r\n .padding()\r\n }</strong>\r\n }\r\n}</pre>\r\nNotice that all the views are now created declaratively using code — no more drag-and-drop in Storyboard. Layouts are now also specified declaratively using code (the <code>VStack</code> in this example stacks all the views vertically). Delegates are now replaced with closures.\r\n\r\nMore important, views are now a function of state (and not a sequence of events) — the text displayed by the <code>Text</code> view is now bound to the state variable <code>label</code>. When the button is tapped, you change the value of the<code> label</code> state variable, which automatically updates the text displayed in the <code>Text</code> view. This programming paradigm is known as <em>reactive programming</em><em>.</em>\r\n\r\nThe image below shows the various views in action.\r\n\r\n[caption id=\"attachment_273771\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-273771 size-full\" src=\"https://www.dummies.com/wp-content/uploads/swiftui.jpg\" alt=\"SwiftUI\" width=\"556\" height=\"561\" /> SwiftUI is a state-driven declarative framework.[/caption]\r\n\r\n \r\n\r\nWant to learn more? Check out our <a href=\"https://www.dummies.com/programming/macintosh/swift/swiftui-for-dummies-cheat-sheet/\" target=\"_blank\" rel=\"noopener\">SwiftUI Cheat Sheet</a>.","description":"SwiftUI is a declarative programming framework for developing UIs for <a href=\"https://www.dummies.com/web-design-development/ios/why-you-should-develop-ios-apps/\" target=\"_blank\" rel=\"noopener\">iOS</a>, iPadOS, watchOS, tvOS, and macOS applications. In fact, SwiftUI was invented by the watchOS group at Apple.\r\n\r\nBefore SwiftUI was introduced, most developers use UIKit and Storyboard (which is still supported by Apple in the current version of Xcode to design a UI. Using UIKit and Storyboard, developers drag and drop View controls onto View Controllers and connect them to outlets and actions on the View Controller classes. This model of building UIs is known as <em>Model View Controller</em> (MVC), which creates a clean separation between UI and business logic.\r\n\r\nThe following shows a simple implementation in UIKit and Storyboard. Here, a <code>Button</code> and <code>Label</code> view have been added to the View Controller in Storyboard; two outlets and an action have been created to connect to them:\r\n<pre class=\"code\">class ViewController: UIViewController {\r\n\r\n <strong> @IBOutlet weak var lbl: UILabel!\r\n @IBOutlet weak var button: UIButton!\r\n @IBAction func btnClicked(_ sender: Any) {\r\n lbl.text = \"Button tapped\"\r\n }</strong></pre>\r\nFor laying out the views, you use auto-layout to position the button and label in the middle of the screen (both horizontally and vertically).\r\n\r\nTo customize the look and feel of the button, you can code it in the <code>loadView()</code> method, like this:\r\n<pre class=\"code\"> override func loadView() {\r\n super.loadView()\r\n\r\n <strong>// background color\r\n button.backgroundColor = UIColor.yellow\r\n\r\n // button text and color\r\n button.setTitle(\"Submit\", for: .normal)\r\n button.setTitleColor(.black, for: .normal)\r\n\r\n // padding\r\n button.contentEdgeInsets = UIEdgeInsets(\r\n top: 10, left: 10, bottom: 10, right: 10)\r\n\r\n // border\r\n button.layer.borderColor =\r\n UIColor.darkGray.cgColor\r\n button.layer.borderWidth = 3.0\r\n\r\n // text font\r\n button.titleLabel!.font =\r\n UIFont.systemFont(ofSize: 26, weight:\r\n UIFont.Weight.regular)\r\n\r\n // rounder corners\r\n button.layer.cornerRadius = 10\r\n\r\n // auto adjust button size\r\n button.sizeToFit()\r\n </strong> }</pre>\r\nThe following image shows the button that has customized. UIKit is an <em>event-driven</em> framework, where you can reference each view in your view controller, update its appearance, or handle an event through <em>delegates</em> when some events occurred.\r\n\r\n[caption id=\"attachment_273770\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-273770 size-full\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-uikit.jpg\" alt=\"UIKit\" width=\"556\" height=\"563\" /> UIKit is event driven, and it uses delegates to handle events.[/caption]\r\n\r\n \r\n\r\nIn contrast, SwiftUI is a <em>state-driven, </em>declarative framework. In SwiftUI, you can implement all the above with the following statements:\r\n<pre class=\"code\">struct ContentView: View {\r\n <strong> @State private var label = \"label\"</strong>\r\n\r\n var body: some View {\r\n <strong>VStack {\r\n Button(action: {\r\n self.label = \"Button tapped\"\r\n }) {\r\n Text(\"Submit\")\r\n .padding(EdgeInsets(\r\n top: 10, leading: 10,\r\n bottom: 10, trailing: 10))\r\n .background(Color.yellow)\r\n .foregroundColor(Color.black)\r\n .border(Color.gray, width: 3)\r\n .font(Font.system(size: 26.0))\r\n .overlay(\r\n RoundedRectangle(cornerRadius: 10)\r\n .stroke(Color.gray,\r\n lineWidth: 5)\r\n </strong> <strong> )\r\n }\r\n Text(label)\r\n .padding()\r\n }</strong>\r\n }\r\n}</pre>\r\nNotice that all the views are now created declaratively using code — no more drag-and-drop in Storyboard. Layouts are now also specified declaratively using code (the <code>VStack</code> in this example stacks all the views vertically). Delegates are now replaced with closures.\r\n\r\nMore important, views are now a function of state (and not a sequence of events) — the text displayed by the <code>Text</code> view is now bound to the state variable <code>label</code>. When the button is tapped, you change the value of the<code> label</code> state variable, which automatically updates the text displayed in the <code>Text</code> view. This programming paradigm is known as <em>reactive programming</em><em>.</em>\r\n\r\nThe image below shows the various views in action.\r\n\r\n[caption id=\"attachment_273771\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-273771 size-full\" src=\"https://www.dummies.com/wp-content/uploads/swiftui.jpg\" alt=\"SwiftUI\" width=\"556\" height=\"561\" /> SwiftUI is a state-driven declarative framework.[/caption]\r\n\r\n \r\n\r\nWant to learn more? Check out our <a href=\"https://www.dummies.com/programming/macintosh/swift/swiftui-for-dummies-cheat-sheet/\" target=\"_blank\" rel=\"noopener\">SwiftUI Cheat Sheet</a>.","blurb":"","authors":[{"authorId":33413,"name":"Wei-Meng Lee","slug":"wei-meng-lee","description":" <p><b>Wei-Meng Lee</b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p> ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33413"}}],"primaryCategoryTaxonomy":{"categoryId":33594,"title":"App Development","slug":"app-development","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33594"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":null,"inThisArticle":[],"relatedArticles":{"fromBook":[{"articleId":274241,"title":"How to Make Your Own Animation in SwiftUI","slug":"how-to-make-your-own-animation-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274241"}},{"articleId":274231,"title":"Understanding How to Animate in SwiftUI","slug":"understanding-how-to-animate-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274231"}},{"articleId":274224,"title":"How to Use UIKit in SwiftUI","slug":"how-to-use-uikit-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274224"}},{"articleId":274217,"title":"Swift Closures","slug":"swift-closures","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274217"}},{"articleId":274211,"title":"A Quick Intro to Swift Functions","slug":"a-quick-intro-to-swift-functions","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274211"}}],"fromCategory":[{"articleId":274241,"title":"How to Make Your Own Animation in SwiftUI","slug":"how-to-make-your-own-animation-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274241"}},{"articleId":274231,"title":"Understanding How to Animate in SwiftUI","slug":"understanding-how-to-animate-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274231"}},{"articleId":274224,"title":"How to Use UIKit in SwiftUI","slug":"how-to-use-uikit-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274224"}},{"articleId":274217,"title":"Swift Closures","slug":"swift-closures","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274217"}},{"articleId":274211,"title":"A Quick Intro to Swift Functions","slug":"a-quick-intro-to-swift-functions","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274211"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281877,"slug":"swiftui-for-dummies","isbn":"9781119652687","categoryList":["technology","programming-web-design","app-development"],"amazon":{"default":"https://www.amazon.com/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119652685-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/swiftui-for-dummies-cover-9781119652687-203x255.jpg","width":203,"height":255},"title":"SwiftUI For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b><b data-author-id=\"33413\">Wei-Meng Lee</b></b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p>","authors":[{"authorId":33413,"name":"Wei-Meng Lee","slug":"wei-meng-lee","description":" <p><b>Wei-Meng Lee</b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p> ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33413"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;app-development&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119652687&quot;]}]\" id=\"du-slot-62f3f261e5bfa\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;app-development&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119652687&quot;]}]\" id=\"du-slot-62f3f261e64a9\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"One year","lifeExpectancySetFrom":"2022-08-10T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":273769},{"headers":{"creationTime":"2020-10-28T20:51:06+00:00","modifiedTime":"2022-08-10T16:44:34+00:00","timestamp":"2022-08-10T18:01:05+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"App Development","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33594"},"slug":"app-development","categoryId":33594}],"title":"A Quick Intro to Swift Functions","strippedTitle":"a quick intro to swift functions","slug":"a-quick-intro-to-swift-functions","canonicalUrl":"","seo":{"metaDescription":"Want to know how to program great iOS apps? SwiftUI is a great tool for exactly that purpose. But first, let's learn about Swift functions.","noIndex":0,"noFollow":0},"content":"Are you ready to <a href=\"https://www.dummies.com/web-design-development/ios/what-makes-a-great-ios-app/\" target=\"_blank\" rel=\"noopener\">build iOS apps</a> using an innovative and intuitive user interface? Then, SwiftUI is for you! But before you dive in, you’ll need to know about Swift functions. Here’s a quick intro.\r\n\r\n[caption id=\"attachment_274212\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-274212 size-full\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-app-developer.jpg\" alt=\"SwiftUI app development\" width=\"556\" height=\"370\" /> ©Shutterstock/baranq[/caption]\r\n\r\nIn Swift, a function is defined using the <code>func</code> keyword, like this:\r\n<pre class=\"code\">func doSomething() {\r\n print(\"doSomething\")\r\n}</pre>\r\nThe preceding code snippet defines a function called <code>doSomething</code>. It does not take in any inputs (known as <em>parameters</em>) and does not return a value (technically, it does return a <code>Void</code> value).\r\n\r\nTo call the function, simply call its name followed by a pair of empty parentheses:\r\n<pre class=\"code\">doSomething()</pre>\r\n<h2 id=\"tab1\" ><a name=\"_Toc273568048\"></a><a name=\"_Toc39248487\"></a>Understanding input parameters</h2>\r\nA function can also optionally define one or more named typed inputs. The following function takes in one single typed input parameter:\r\n<pre class=\"code\">func doSomething(num: Int) {\r\n print(num)\r\n}</pre>\r\nTo call this function, call its name and pass in an integer value (known as an <em>argument</em>) with the parameter name, like this:\r\n<pre class=\"code\">doSomething(num: 5)</pre>\r\nThe following function takes in two input parameters, both of type Int:\r\n<pre class=\"code\">func doSomething(num1: Int, num2: Int) {\r\n print(num1, num2)\r\n}</pre>\r\nTo call this function, pass it two integer values as the argument:\r\n<pre class=\"code\">doSomething(num1: 5, num2: 6)</pre>\r\n<h2 id=\"tab2\" ><a name=\"_Toc39248488\"></a><a name=\"_Toc273568049\"></a>Returning a value</h2>\r\nFunctions are not required to return a value. However, if you want the function to return a value, use the -> operator after the function declaration. The following function returns an integer value:\r\n<pre class=\"code\">func doSomething(num1: Int, num2: Int, num3: Int) -> Int {\r\n return num1 + num2 + num3\r\n}</pre>\r\nYou use the <code>return</code> keyword to return a value from a function and then exit it. When the function returns a value, you can assign it to a variable or constant, like this:\r\n<pre class=\"code\">var sum = doSomething(num1:5, num2:6, num3: 7)</pre>\r\n<p class=\"article-tips tip\">Functions are not limited to returning a single value. In some cases, it’s important for functions to return multiple values (or even functions). In Swift, you can use a tuple type in a function to return multiple values.</p>\r\nWant to learn more? Check out these <a href=\"https://www.dummies.com/programming/macintosh/9-swiftui-tips-and-tricks/\" target=\"_blank\" rel=\"noopener\">SwiftUI tips and tricks</a>.","description":"Are you ready to <a href=\"https://www.dummies.com/web-design-development/ios/what-makes-a-great-ios-app/\" target=\"_blank\" rel=\"noopener\">build iOS apps</a> using an innovative and intuitive user interface? Then, SwiftUI is for you! But before you dive in, you’ll need to know about Swift functions. Here’s a quick intro.\r\n\r\n[caption id=\"attachment_274212\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-274212 size-full\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-app-developer.jpg\" alt=\"SwiftUI app development\" width=\"556\" height=\"370\" /> ©Shutterstock/baranq[/caption]\r\n\r\nIn Swift, a function is defined using the <code>func</code> keyword, like this:\r\n<pre class=\"code\">func doSomething() {\r\n print(\"doSomething\")\r\n}</pre>\r\nThe preceding code snippet defines a function called <code>doSomething</code>. It does not take in any inputs (known as <em>parameters</em>) and does not return a value (technically, it does return a <code>Void</code> value).\r\n\r\nTo call the function, simply call its name followed by a pair of empty parentheses:\r\n<pre class=\"code\">doSomething()</pre>\r\n<h2 id=\"tab1\" ><a name=\"_Toc273568048\"></a><a name=\"_Toc39248487\"></a>Understanding input parameters</h2>\r\nA function can also optionally define one or more named typed inputs. The following function takes in one single typed input parameter:\r\n<pre class=\"code\">func doSomething(num: Int) {\r\n print(num)\r\n}</pre>\r\nTo call this function, call its name and pass in an integer value (known as an <em>argument</em>) with the parameter name, like this:\r\n<pre class=\"code\">doSomething(num: 5)</pre>\r\nThe following function takes in two input parameters, both of type Int:\r\n<pre class=\"code\">func doSomething(num1: Int, num2: Int) {\r\n print(num1, num2)\r\n}</pre>\r\nTo call this function, pass it two integer values as the argument:\r\n<pre class=\"code\">doSomething(num1: 5, num2: 6)</pre>\r\n<h2 id=\"tab2\" ><a name=\"_Toc39248488\"></a><a name=\"_Toc273568049\"></a>Returning a value</h2>\r\nFunctions are not required to return a value. However, if you want the function to return a value, use the -> operator after the function declaration. The following function returns an integer value:\r\n<pre class=\"code\">func doSomething(num1: Int, num2: Int, num3: Int) -> Int {\r\n return num1 + num2 + num3\r\n}</pre>\r\nYou use the <code>return</code> keyword to return a value from a function and then exit it. When the function returns a value, you can assign it to a variable or constant, like this:\r\n<pre class=\"code\">var sum = doSomething(num1:5, num2:6, num3: 7)</pre>\r\n<p class=\"article-tips tip\">Functions are not limited to returning a single value. In some cases, it’s important for functions to return multiple values (or even functions). In Swift, you can use a tuple type in a function to return multiple values.</p>\r\nWant to learn more? Check out these <a href=\"https://www.dummies.com/programming/macintosh/9-swiftui-tips-and-tricks/\" target=\"_blank\" rel=\"noopener\">SwiftUI tips and tricks</a>.","blurb":"","authors":[{"authorId":33413,"name":"Wei-Meng Lee","slug":"wei-meng-lee","description":" <p><b>Wei-Meng Lee</b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p> ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33413"}}],"primaryCategoryTaxonomy":{"categoryId":33594,"title":"App Development","slug":"app-development","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33594"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":null,"inThisArticle":[{"label":"Understanding input parameters","target":"#tab1"},{"label":"Returning a value","target":"#tab2"}],"relatedArticles":{"fromBook":[{"articleId":274241,"title":"How to Make Your Own Animation in SwiftUI","slug":"how-to-make-your-own-animation-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274241"}},{"articleId":274231,"title":"Understanding How to Animate in SwiftUI","slug":"understanding-how-to-animate-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274231"}},{"articleId":274224,"title":"How to Use UIKit in SwiftUI","slug":"how-to-use-uikit-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274224"}},{"articleId":274217,"title":"Swift Closures","slug":"swift-closures","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274217"}},{"articleId":274206,"title":"10 Great SwiftUI Resources","slug":"10-great-swiftui-resources","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274206"}}],"fromCategory":[{"articleId":274241,"title":"How to Make Your Own Animation in SwiftUI","slug":"how-to-make-your-own-animation-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274241"}},{"articleId":274231,"title":"Understanding How to Animate in SwiftUI","slug":"understanding-how-to-animate-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274231"}},{"articleId":274224,"title":"How to Use UIKit in SwiftUI","slug":"how-to-use-uikit-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274224"}},{"articleId":274217,"title":"Swift Closures","slug":"swift-closures","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274217"}},{"articleId":274206,"title":"10 Great SwiftUI Resources","slug":"10-great-swiftui-resources","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274206"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281877,"slug":"swiftui-for-dummies","isbn":"9781119652687","categoryList":["technology","programming-web-design","app-development"],"amazon":{"default":"https://www.amazon.com/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119652685-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/swiftui-for-dummies-cover-9781119652687-203x255.jpg","width":203,"height":255},"title":"SwiftUI For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b><b data-author-id=\"33413\">Wei-Meng Lee</b></b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p>","authors":[{"authorId":33413,"name":"Wei-Meng Lee","slug":"wei-meng-lee","description":" <p><b>Wei-Meng Lee</b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p> ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33413"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;app-development&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119652687&quot;]}]\" id=\"du-slot-62f3f261dd6fb\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;app-development&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119652687&quot;]}]\" id=\"du-slot-62f3f261de003\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"One year","lifeExpectancySetFrom":"2022-08-10T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":274211},{"headers":{"creationTime":"2020-09-21T18:48:55+00:00","modifiedTime":"2022-08-10T16:42:46+00:00","timestamp":"2022-08-10T18:01:05+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Social Media","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33611"},"slug":"social-media","categoryId":33611},{"name":"YouTube","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33616"},"slug":"youtube","categoryId":33616}],"title":"Understanding Your YouTube Channel Audience","strippedTitle":"understanding your youtube channel audience","slug":"understanding-your-youtube-channel-audience","canonicalUrl":"","seo":{"metaDescription":"Promoting your YouTube channel is important for those looking to be successful YouTubers. Use this guide to gain insight into your audience.","noIndex":0,"noFollow":0},"content":"Video reports and audience retention graphs are designed to help you understand how well your viewers are responding to your <a href=\"https://www.dummies.com/social-media/youtube/creating-great-youtube-content/\" target=\"_blank\" rel=\"noopener\">YouTube channel content</a>. To find out who’s watching your YouTube videos, you have to try a different tack: check out YouTube’s audience reports.\r\n<h2 id=\"tab1\" ><a name=\"_Toc42547824\"></a>Diving into YouTube’s demographics metrics</h2>\r\nIt helps to know who’s watching your YouTube content so that you can make important content-planning decisions. The Audience tab of <a href=\"https://www.dummies.com/social-media/youtube/getting-started-with-youtube-analytics/\" target=\"_blank\" rel=\"noopener\">YouTube Analytics</a> is a fascinating way to analyze your channel demographics, because you can get concrete information about your audience members’ gender, age, and country of residence.\r\n<p class=\"article-tips remember\">Certain audience reports allow you to filter to see results explicitly from your subscriber base. Sometimes, it’s interesting to see whether your subscriber demographics mirror your general audience demographics.</p>\r\nTo access audience reports, follow these steps:\r\n<ol>\r\n \t<li>Go to <a href=\"http://www.youtube.com/\" target=\"_blank\" rel=\"noopener\">YouTube</a>.</li>\r\n \t<li>Log on to your YouTube account.If you see the blue Sign In button in the top right corner of the YouTube home page, enter your email address and password.</li>\r\n \t<li>Click the Logged-In icon and choose YouTube Studio from the menu that appears.The YouTube Studio navigation menu should appear on the left side of your browser.</li>\r\n \t<li>Choose Analytics from the navigation menu.</li>\r\n \t<li>Click to open the Audience tab on the Reports menu.Here you find summary reports of age and gender.\r\n\r\n[caption id=\"attachment_273537\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-273537 size-full\" src=\"https://www.dummies.com/wp-content/uploads/youtube-channels-analytics-reports.jpg\" alt=\"YouTube Analytics\" width=\"556\" height=\"416\" /> YouTube Analytics age-and-gender report.[/caption]</li>\r\n \t<li>Click the See More link at the bottom of the Age and Gender summary report, and examine the charts and their accompanying details.It’s terrific if your audience is exactly what you thought it would be. If it isn’t, revisit your assumptions. You may find that your content is having wider interest, which may be a good thing. Conversely, if you’re not seeing enough traction, perhaps you’re not engaging enough with key creators and fans in your core demographic to help you get the word out.</li>\r\n \t<li>Refine the report to show only subscribed viewers by choosing Subscription Status from the filter drop-down menu.Look closely at how the graphs change. If you see a big difference, determine whether subscription requests are working more broadly than expected, because your content certainly is appealing to others.</li>\r\n</ol>\r\n<p class=\"article-tips tip\">Make it a habit to compare your demographic information over time to detect any shifts in your audience.</p>\r\n\r\n<h2 id=\"tab2\" ><a name=\"_Toc42547825\"></a>Diving into YouTube subscribers metrics</h2>\r\nKnowing your YouTube subscribers’ patterns and where they’re doing their subscribing is an important part of your channel management responsibilities. YouTube is well aware of that, which is why it offers a subscription source report as part of YouTube Analytics. Here’s how to access it:\r\n<ol>\r\n \t<li>Go to <a href=\"http://www.youtube.com/\" target=\"_blank\" rel=\"noopener\">YouTube</a>.</li>\r\n \t<li>Log on to your YouTube account.If you see the blue Sign In button in the top right corner of the YouTube home page, enter your email address and password.</li>\r\n \t<li>Click the Logged-In icon and choose YouTube Studio from the menu that appears.The YouTube Studio navigation menu should appear on the left side of your browser.</li>\r\n \t<li>Bring up the Analytics section of YouTube Studio.</li>\r\n \t<li>Click on Advanced Mode from the top right of the screen.Within the Advanced Mode window, click on More from the Reports menu and find the Subscription Source option.</li>\r\n \t<li>Look at the report’s table section to see where on YouTube your audience subscribes to your channel.In addition to subscriber gains, you see the number of subscribers lost, too, which is a normal part of channel activity.\r\n\r\n[caption id=\"attachment_273538\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-273538 size-full\" src=\"https://www.dummies.com/wp-content/uploads/youtube-channels-subscribers.jpg\" alt=\"YouTube subscribers report\" width=\"556\" height=\"416\" /> YouTube subscribers report.[/caption]</li>\r\n</ol>\r\nInterested in learning more? Check out our <a href=\"https://www.dummies.com/social-media/youtube/youtube-channels-for-dummies-cheat-sheet/\" target=\"_blank\" rel=\"noopener\">YouTube Channels Cheat Sheet</a>.","description":"Video reports and audience retention graphs are designed to help you understand how well your viewers are responding to your <a href=\"https://www.dummies.com/social-media/youtube/creating-great-youtube-content/\" target=\"_blank\" rel=\"noopener\">YouTube channel content</a>. To find out who’s watching your YouTube videos, you have to try a different tack: check out YouTube’s audience reports.\r\n<h2 id=\"tab1\" ><a name=\"_Toc42547824\"></a>Diving into YouTube’s demographics metrics</h2>\r\nIt helps to know who’s watching your YouTube content so that you can make important content-planning decisions. The Audience tab of <a href=\"https://www.dummies.com/social-media/youtube/getting-started-with-youtube-analytics/\" target=\"_blank\" rel=\"noopener\">YouTube Analytics</a> is a fascinating way to analyze your channel demographics, because you can get concrete information about your audience members’ gender, age, and country of residence.\r\n<p class=\"article-tips remember\">Certain audience reports allow you to filter to see results explicitly from your subscriber base. Sometimes, it’s interesting to see whether your subscriber demographics mirror your general audience demographics.</p>\r\nTo access audience reports, follow these steps:\r\n<ol>\r\n \t<li>Go to <a href=\"http://www.youtube.com/\" target=\"_blank\" rel=\"noopener\">YouTube</a>.</li>\r\n \t<li>Log on to your YouTube account.If you see the blue Sign In button in the top right corner of the YouTube home page, enter your email address and password.</li>\r\n \t<li>Click the Logged-In icon and choose YouTube Studio from the menu that appears.The YouTube Studio navigation menu should appear on the left side of your browser.</li>\r\n \t<li>Choose Analytics from the navigation menu.</li>\r\n \t<li>Click to open the Audience tab on the Reports menu.Here you find summary reports of age and gender.\r\n\r\n[caption id=\"attachment_273537\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-273537 size-full\" src=\"https://www.dummies.com/wp-content/uploads/youtube-channels-analytics-reports.jpg\" alt=\"YouTube Analytics\" width=\"556\" height=\"416\" /> YouTube Analytics age-and-gender report.[/caption]</li>\r\n \t<li>Click the See More link at the bottom of the Age and Gender summary report, and examine the charts and their accompanying details.It’s terrific if your audience is exactly what you thought it would be. If it isn’t, revisit your assumptions. You may find that your content is having wider interest, which may be a good thing. Conversely, if you’re not seeing enough traction, perhaps you’re not engaging enough with key creators and fans in your core demographic to help you get the word out.</li>\r\n \t<li>Refine the report to show only subscribed viewers by choosing Subscription Status from the filter drop-down menu.Look closely at how the graphs change. If you see a big difference, determine whether subscription requests are working more broadly than expected, because your content certainly is appealing to others.</li>\r\n</ol>\r\n<p class=\"article-tips tip\">Make it a habit to compare your demographic information over time to detect any shifts in your audience.</p>\r\n\r\n<h2 id=\"tab2\" ><a name=\"_Toc42547825\"></a>Diving into YouTube subscribers metrics</h2>\r\nKnowing your YouTube subscribers’ patterns and where they’re doing their subscribing is an important part of your channel management responsibilities. YouTube is well aware of that, which is why it offers a subscription source report as part of YouTube Analytics. Here’s how to access it:\r\n<ol>\r\n \t<li>Go to <a href=\"http://www.youtube.com/\" target=\"_blank\" rel=\"noopener\">YouTube</a>.</li>\r\n \t<li>Log on to your YouTube account.If you see the blue Sign In button in the top right corner of the YouTube home page, enter your email address and password.</li>\r\n \t<li>Click the Logged-In icon and choose YouTube Studio from the menu that appears.The YouTube Studio navigation menu should appear on the left side of your browser.</li>\r\n \t<li>Bring up the Analytics section of YouTube Studio.</li>\r\n \t<li>Click on Advanced Mode from the top right of the screen.Within the Advanced Mode window, click on More from the Reports menu and find the Subscription Source option.</li>\r\n \t<li>Look at the report’s table section to see where on YouTube your audience subscribes to your channel.In addition to subscriber gains, you see the number of subscribers lost, too, which is a normal part of channel activity.\r\n\r\n[caption id=\"attachment_273538\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-273538 size-full\" src=\"https://www.dummies.com/wp-content/uploads/youtube-channels-subscribers.jpg\" alt=\"YouTube subscribers report\" width=\"556\" height=\"416\" /> YouTube subscribers report.[/caption]</li>\r\n</ol>\r\nInterested in learning more? Check out our <a href=\"https://www.dummies.com/social-media/youtube/youtube-channels-for-dummies-cheat-sheet/\" target=\"_blank\" rel=\"noopener\">YouTube Channels Cheat Sheet</a>.","blurb":"","authors":[{"authorId":9202,"name":"Rob Ciampa","slug":"rob-ciampa","description":" <p><b>Rob Ciampa</b> works with worldwide brands, agencies, and business leaders on sales, marketing, and YouTube strategies. <b>Theresa Go</b> is Vice President of Platform Partnerships for Pixability. <b>Matt Ciampa</b> has been a professional YouTube video creator and producer for more than a decade. <b>Rich Murphy</b> is a Product Manager at Pixability and an expert on YouTube advertising and analytics. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/9202"}},{"authorId":33416,"name":"Theresa Go","slug":"theresa-go","description":" <p><b>Rob Ciampa</b> works with worldwide brands, agencies, and business leaders on sales, marketing, and YouTube strategies. <b>Theresa Go</b> is Vice President of Platform Partnerships for Pixability. <b>Matt Ciampa</b> has been a professional YouTube video creator and producer for more than a decade. <b>Rich Murphy</b> is a Product Manager at Pixability and an expert on YouTube advertising and analytics. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33416"}},{"authorId":33417,"name":"Matt Ciampa","slug":"matt-ciampa","description":" <p><b>Rob Ciampa</b> works with worldwide brands, agencies, and business leaders on sales, marketing, and YouTube strategies. <b>Theresa Go</b> is Vice President of Platform Partnerships for Pixability. <b>Matt Ciampa</b> has been a professional YouTube video creator and producer for more than a decade. <b>Rich Murphy</b> is a Product Manager at Pixability and an expert on YouTube advertising and analytics. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33417"}},{"authorId":33418,"name":"Rich Murphy","slug":"rich-murphy","description":" <p><b>Rob Ciampa</b> works with worldwide brands, agencies, and business leaders on sales, marketing, and YouTube strategies. <b>Theresa Go</b> is Vice President of Platform Partnerships for Pixability. <b>Matt Ciampa</b> has been a professional YouTube video creator and producer for more than a decade. <b>Rich Murphy</b> is a Product Manager at Pixability and an expert on YouTube advertising and analytics. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33418"}}],"primaryCategoryTaxonomy":{"categoryId":33616,"title":"YouTube","slug":"youtube","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33616"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":null,"inThisArticle":[{"label":"Diving into YouTube’s demographics metrics","target":"#tab1"},{"label":"Diving into YouTube subscribers metrics","target":"#tab2"}],"relatedArticles":{"fromBook":[{"articleId":273522,"title":"Getting Started with YouTube Analytics","slug":"getting-started-with-youtube-analytics","categoryList":["technology","social-media","youtube"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/273522"}},{"articleId":273516,"title":"How to Add Music to Your YouTube Video","slug":"how-to-add-music-to-your-youtube-video","categoryList":["technology","social-media","youtube"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/273516"}},{"articleId":273510,"title":"Making a Content Strategy for Your YouTube Channel","slug":"making-a-content-strategy-for-your-youtube-channel","categoryList":["technology","social-media","youtube"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/273510"}},{"articleId":207547,"title":"YouTube Channels For Dummies Cheat Sheet","slug":"youtube-channels-for-dummies-cheat-sheet","categoryList":["technology","social-media","youtube"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/207547"}},{"articleId":203260,"title":"How to Create a YouTube Channel","slug":"how-to-create-a-youtube-channel","categoryList":["technology","social-media","youtube"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/203260"}}],"fromCategory":[{"articleId":273522,"title":"Getting Started with YouTube Analytics","slug":"getting-started-with-youtube-analytics","categoryList":["technology","social-media","youtube"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/273522"}},{"articleId":273516,"title":"How to Add Music to Your YouTube Video","slug":"how-to-add-music-to-your-youtube-video","categoryList":["technology","social-media","youtube"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/273516"}},{"articleId":273510,"title":"Making a Content Strategy for Your YouTube Channel","slug":"making-a-content-strategy-for-your-youtube-channel","categoryList":["technology","social-media","youtube"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/273510"}},{"articleId":258541,"title":"How to Use YouTube as a Marketing Channel","slug":"how-to-use-youtube-as-a-marketing-channel","categoryList":["technology","social-media","youtube"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/258541"}},{"articleId":239597,"title":"How to Download YouTube Videos","slug":"download-youtube-videos","categoryList":["technology","social-media","youtube"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/239597"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281906,"slug":"youtube-channels-for-dummies-2nd-edition","isbn":"9781119688051","categoryList":["technology","social-media","youtube"],"amazon":{"default":"https://www.amazon.com/gp/product/1119688051/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119688051/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119688051-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119688051/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119688051/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/youtube-channels-for-dummies-2nd-edition-cover-9781119688051-203x255.jpg","width":203,"height":255},"title":"YouTube Channels For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><p><b><b data-author-id=\"9202\">Rob Ciampa</b></b> works with worldwide brands, agencies, and business leaders on sales, marketing, and YouTube strategies. <b>Theresa Go</b> is Vice President of Platform Partnerships for Pixability. <b>Matt Ciampa</b> has been a professional YouTube video creator and producer for more than a decade. <b>Rich Murphy</b> is a Product Manager at Pixability and an expert on YouTube advertising and analytics. <p><b>Rob Ciampa</b> works with worldwide brands, agencies, and business leaders on sales, marketing, and YouTube strategies. <b><b data-author-id=\"33416\">Theresa Go</b></b> is Vice President of Platform Partnerships for Pixability. <b>Matt Ciampa</b> has been a professional YouTube video creator and producer for more than a decade. <b>Rich Murphy</b> is a Product Manager at Pixability and an expert on YouTube advertising and analytics. <p><b>Rob Ciampa</b> works with worldwide brands, agencies, and business leaders on sales, marketing, and YouTube strategies. <b>Theresa Go</b> is Vice President of Platform Partnerships for Pixability. <b><b data-author-id=\"33417\">Matt Ciampa</b></b> has been a professional YouTube video creator and producer for more than a decade. <b>Rich Murphy</b> is a Product Manager at Pixability and an expert on YouTube advertising and analytics. <p><b>Rob Ciampa</b> works with worldwide brands, agencies, and business leaders on sales, marketing, and YouTube strategies. <b>Theresa Go</b> is Vice President of Platform Partnerships for Pixability. <b>Matt Ciampa</b> has been a professional YouTube video creator and producer for more than a decade. <b><b data-author-id=\"33418\">Rich Murphy</b></b> is a Product Manager at Pixability and an expert on YouTube advertising and analytics.</p>","authors":[{"authorId":9202,"name":"Rob Ciampa","slug":"rob-ciampa","description":" <p><b>Rob Ciampa</b> works with worldwide brands, agencies, and business leaders on sales, marketing, and YouTube strategies. <b>Theresa Go</b> is Vice President of Platform Partnerships for Pixability. <b>Matt Ciampa</b> has been a professional YouTube video creator and producer for more than a decade. <b>Rich Murphy</b> is a Product Manager at Pixability and an expert on YouTube advertising and analytics. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/9202"}},{"authorId":33416,"name":"Theresa Go","slug":"theresa-go","description":" <p><b>Rob Ciampa</b> works with worldwide brands, agencies, and business leaders on sales, marketing, and YouTube strategies. <b>Theresa Go</b> is Vice President of Platform Partnerships for Pixability. <b>Matt Ciampa</b> has been a professional YouTube video creator and producer for more than a decade. <b>Rich Murphy</b> is a Product Manager at Pixability and an expert on YouTube advertising and analytics. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33416"}},{"authorId":33417,"name":"Matt Ciampa","slug":"matt-ciampa","description":" <p><b>Rob Ciampa</b> works with worldwide brands, agencies, and business leaders on sales, marketing, and YouTube strategies. <b>Theresa Go</b> is Vice President of Platform Partnerships for Pixability. <b>Matt Ciampa</b> has been a professional YouTube video creator and producer for more than a decade. <b>Rich Murphy</b> is a Product Manager at Pixability and an expert on YouTube advertising and analytics. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33417"}},{"authorId":33418,"name":"Rich Murphy","slug":"rich-murphy","description":" <p><b>Rob Ciampa</b> works with worldwide brands, agencies, and business leaders on sales, marketing, and YouTube strategies. <b>Theresa Go</b> is Vice President of Platform Partnerships for Pixability. <b>Matt Ciampa</b> has been a professional YouTube video creator and producer for more than a decade. <b>Rich Murphy</b> is a Product Manager at Pixability and an expert on YouTube advertising and analytics. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33418"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;social-media&quot;,&quot;youtube&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119688051&quot;]}]\" id=\"du-slot-62f3f261d60bd\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;social-media&quot;,&quot;youtube&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119688051&quot;]}]\" id=\"du-slot-62f3f261d694d\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Explore","lifeExpectancy":"One year","lifeExpectancySetFrom":"2022-08-10T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":273536},{"headers":{"creationTime":"2020-10-27T19:54:57+00:00","modifiedTime":"2022-08-10T16:37:56+00:00","timestamp":"2022-08-10T18:01:05+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"App Development","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33594"},"slug":"app-development","categoryId":33594}],"title":"A Brief Primer on Swift Programming: Basic Syntax","strippedTitle":"a brief primer on swift programming: basic syntax","slug":"a-brief-primer-on-swift-programming-basic-syntax","canonicalUrl":"","seo":{"metaDescription":"Want to learn the basics of Swift programming? This brief primer teaches you how the basics of Swift syntax, from Dummies.com.","noIndex":0,"noFollow":0},"content":"Swift is a <em>type-safe language,</em> which means that the programming language makes it clear to you the types of values your code is working with. The following article discusses how to declare constants and variables and how to work with strings and comments when programming with Swift.\r\n<h2 id=\"tab1\" ><a name=\"_Toc273410879\"></a><a name=\"_Toc39248462\"></a>Swift constants</h2>\r\nIn Swift, you create a constant using the let keyword:\r\n<pre class=\"code\">let radius = 3.45 // Double\r\nlet numOfColumns = 5 // Int\r\nlet myName = \"Wei-Meng Lee\" // String</pre>\r\nNotice that there is no need to specify the data type — the data types are inferred automatically.\r\n\r\nIf you want to declare the type of constant, you can do so using the colon operator (:) followed by the data type, as shown here:\r\n<pre class=\"code\">let diameter<strong>:Double</strong> = 8</pre>\r\n<p class=\"article-tips remember\">After a constant is created, you can no longer change its value. Always use a let when you need to store values that do not change.</p>\r\n\r\n<h2 id=\"tab2\" ><a name=\"_Toc273410880\"></a><a name=\"_Toc39248463\"></a>Swift variables</h2>\r\nTo declare a variable, you use the var keyword:\r\n<pre class=\"code\">var myAge = 25\r\nvar circumference = 2 * 3.14 * radius</pre>\r\nAfter a variable is created, you can change its value. In Swift, values are never implicitly converted to another type. For example, suppose you’re trying to concatenate a string and the value of a variable. In the following example, you need to explicitly use the String() function to convert the value of myAge to a string value before concatenating it with another string:\r\n<pre class=\"code\">var strMyAge = \"My age is \" + String(myAge)</pre>\r\n<p class=\"article-tips remember\">To get the text representation of a value (constant or variable), you can also use the description property, like this: myAge.description.</p>\r\n\r\n<h2 id=\"tab3\" ><a name=\"_Toc273410881\"></a><a name=\"_Toc39248464\"></a>Swift strings</h2>\r\nOne of the common tasks in programming is inserting values of variables into a string. In Swift, you use <em>string interpolation</em> and it has the following format:\r\n<pre class=\"code\">\"Your string literal <strong>\\(</strong><em>variable_name</em><strong>)</strong>\"</pre>\r\nThe following statement shows an example:\r\n<pre class=\"code\">let firstName = \"Wei-Meng\"\r\nlet lastName = \"Lee\"\r\nvar strName = \"My name is \\(firstName) \\(lastName)\"</pre>\r\nYou can also use this method to include a Double value in your string (or even perform mathematical operations or function calls):\r\n<pre class=\"code\">var strResult = \"The circumference is \\(circumference)\"</pre>\r\n<h2 id=\"tab4\" ><a name=\"_Toc273410884\"></a><a name=\"_Toc39248465\"></a>Swift comments</h2>\r\nIn Swift, as in most <a href=\"https://www.dummies.com/programming/the-types-of-programming-languages/\" target=\"_blank\" rel=\"noopener\">programming languages</a>, you insert comments into your code using two forward slashes (//):\r\n<pre class=\"code\">// this is another comment</pre>\r\nIf you have several lines of comments, it’s better to use the /* and */ combination to denote a block of statements as comments:\r\n<pre class=\"code\">/*\r\n this is a comment\r\n this is another comment\r\n*/</pre>\r\nWant to learn more? Check out our <a href=\"https://www.dummies.com/programming/macintosh/swift/swiftui-for-dummies-cheat-sheet/\" target=\"_blank\" rel=\"noopener\">SwiftUI Cheat Sheet</a>.","description":"Swift is a <em>type-safe language,</em> which means that the programming language makes it clear to you the types of values your code is working with. The following article discusses how to declare constants and variables and how to work with strings and comments when programming with Swift.\r\n<h2 id=\"tab1\" ><a name=\"_Toc273410879\"></a><a name=\"_Toc39248462\"></a>Swift constants</h2>\r\nIn Swift, you create a constant using the let keyword:\r\n<pre class=\"code\">let radius = 3.45 // Double\r\nlet numOfColumns = 5 // Int\r\nlet myName = \"Wei-Meng Lee\" // String</pre>\r\nNotice that there is no need to specify the data type — the data types are inferred automatically.\r\n\r\nIf you want to declare the type of constant, you can do so using the colon operator (:) followed by the data type, as shown here:\r\n<pre class=\"code\">let diameter<strong>:Double</strong> = 8</pre>\r\n<p class=\"article-tips remember\">After a constant is created, you can no longer change its value. Always use a let when you need to store values that do not change.</p>\r\n\r\n<h2 id=\"tab2\" ><a name=\"_Toc273410880\"></a><a name=\"_Toc39248463\"></a>Swift variables</h2>\r\nTo declare a variable, you use the var keyword:\r\n<pre class=\"code\">var myAge = 25\r\nvar circumference = 2 * 3.14 * radius</pre>\r\nAfter a variable is created, you can change its value. In Swift, values are never implicitly converted to another type. For example, suppose you’re trying to concatenate a string and the value of a variable. In the following example, you need to explicitly use the String() function to convert the value of myAge to a string value before concatenating it with another string:\r\n<pre class=\"code\">var strMyAge = \"My age is \" + String(myAge)</pre>\r\n<p class=\"article-tips remember\">To get the text representation of a value (constant or variable), you can also use the description property, like this: myAge.description.</p>\r\n\r\n<h2 id=\"tab3\" ><a name=\"_Toc273410881\"></a><a name=\"_Toc39248464\"></a>Swift strings</h2>\r\nOne of the common tasks in programming is inserting values of variables into a string. In Swift, you use <em>string interpolation</em> and it has the following format:\r\n<pre class=\"code\">\"Your string literal <strong>\\(</strong><em>variable_name</em><strong>)</strong>\"</pre>\r\nThe following statement shows an example:\r\n<pre class=\"code\">let firstName = \"Wei-Meng\"\r\nlet lastName = \"Lee\"\r\nvar strName = \"My name is \\(firstName) \\(lastName)\"</pre>\r\nYou can also use this method to include a Double value in your string (or even perform mathematical operations or function calls):\r\n<pre class=\"code\">var strResult = \"The circumference is \\(circumference)\"</pre>\r\n<h2 id=\"tab4\" ><a name=\"_Toc273410884\"></a><a name=\"_Toc39248465\"></a>Swift comments</h2>\r\nIn Swift, as in most <a href=\"https://www.dummies.com/programming/the-types-of-programming-languages/\" target=\"_blank\" rel=\"noopener\">programming languages</a>, you insert comments into your code using two forward slashes (//):\r\n<pre class=\"code\">// this is another comment</pre>\r\nIf you have several lines of comments, it’s better to use the /* and */ combination to denote a block of statements as comments:\r\n<pre class=\"code\">/*\r\n this is a comment\r\n this is another comment\r\n*/</pre>\r\nWant to learn more? Check out our <a href=\"https://www.dummies.com/programming/macintosh/swift/swiftui-for-dummies-cheat-sheet/\" target=\"_blank\" rel=\"noopener\">SwiftUI Cheat Sheet</a>.","blurb":"","authors":[{"authorId":33413,"name":"Wei-Meng Lee","slug":"wei-meng-lee","description":" <p><b>Wei-Meng Lee</b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p> ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33413"}}],"primaryCategoryTaxonomy":{"categoryId":33594,"title":"App Development","slug":"app-development","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33594"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":null,"inThisArticle":[{"label":"Swift constants","target":"#tab1"},{"label":"Swift variables","target":"#tab2"},{"label":"Swift strings","target":"#tab3"},{"label":"Swift comments","target":"#tab4"}],"relatedArticles":{"fromBook":[{"articleId":274241,"title":"How to Make Your Own Animation in SwiftUI","slug":"how-to-make-your-own-animation-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274241"}},{"articleId":274231,"title":"Understanding How to Animate in SwiftUI","slug":"understanding-how-to-animate-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274231"}},{"articleId":274224,"title":"How to Use UIKit in SwiftUI","slug":"how-to-use-uikit-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274224"}},{"articleId":274217,"title":"Swift Closures","slug":"swift-closures","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274217"}},{"articleId":274211,"title":"A Quick Intro to Swift Functions","slug":"a-quick-intro-to-swift-functions","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274211"}}],"fromCategory":[{"articleId":274241,"title":"How to Make Your Own Animation in SwiftUI","slug":"how-to-make-your-own-animation-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274241"}},{"articleId":274231,"title":"Understanding How to Animate in SwiftUI","slug":"understanding-how-to-animate-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274231"}},{"articleId":274224,"title":"How to Use UIKit in SwiftUI","slug":"how-to-use-uikit-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274224"}},{"articleId":274217,"title":"Swift Closures","slug":"swift-closures","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274217"}},{"articleId":274211,"title":"A Quick Intro to Swift Functions","slug":"a-quick-intro-to-swift-functions","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274211"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281877,"slug":"swiftui-for-dummies","isbn":"9781119652687","categoryList":["technology","programming-web-design","app-development"],"amazon":{"default":"https://www.amazon.com/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119652685-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/swiftui-for-dummies-cover-9781119652687-203x255.jpg","width":203,"height":255},"title":"SwiftUI For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b><b data-author-id=\"33413\">Wei-Meng Lee</b></b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p>","authors":[{"authorId":33413,"name":"Wei-Meng Lee","slug":"wei-meng-lee","description":" <p><b>Wei-Meng Lee</b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p> ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33413"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;app-development&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119652687&quot;]}]\" id=\"du-slot-62f3f261ca9ff\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;app-development&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119652687&quot;]}]\" id=\"du-slot-62f3f261cb3d2\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"One year","lifeExpectancySetFrom":"2022-08-10T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":274150},{"headers":{"creationTime":"2020-10-28T21:22:20+00:00","modifiedTime":"2022-08-10T16:35:01+00:00","timestamp":"2022-08-10T18:01:05+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"App Development","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33594"},"slug":"app-development","categoryId":33594}],"title":"Swift Closures","strippedTitle":"swift closures","slug":"swift-closures","canonicalUrl":"","seo":{"metaDescription":"Want to make better iOS apps?You're in luck! Discover Swift closures and level up your Swift programming game, from Dummies.com.","noIndex":0,"noFollow":0},"content":"One important feature in <a href=\"https://www.dummies.com/programming/macintosh/swift/what-is-swift-programming-understanding-what-swiftui-is/\" target=\"_blank\" rel=\"noopener\">Swift</a> is <em>closure</em><em>.</em> Closures are self-contained blocks of code that can be passed to functions to be executed as independent code units. Think of a closure as a function without a name. In fact, functions are actually special cases of closures.\r\n\r\n[caption id=\"attachment_274218\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-274218 size-full\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-developing-apps.jpg\" alt=\"SwiftUI app development \" width=\"556\" height=\"370\" /> ©Shutterstock/NDAB Creativity[/caption]\r\n\r\nSwift offers various ways to optimize closures so that they’re brief and succinct. The various optimizations include the following:\r\n<ul>\r\n \t<li>Inferring parameter types and return types</li>\r\n \t<li>Implicit returns from single-statement closures</li>\r\n \t<li>Shorthand argument names</li>\r\n \t<li>Trailing closure syntax</li>\r\n \t<li>Operator closure</li>\r\n</ul>\r\n<h2 id=\"tab1\" ><a name=\"_Toc39248510\"></a><a name=\"_Toc270097018\"></a>Understanding Swift closures</h2>\r\nThe best way to understand Swift closures is to use an example. Suppose you have the following array of integers:\r\n<pre class=\"code\">let numbers = [5,2,8,7,9,4,3,1]</pre>\r\nAssume you want to sort this array in ascending order. You could write your own function to perform the sorting, or you could use the <code>sorted()</code> function available in Swift. The<code> sorted()</code> function takes two arguments:\r\n<ul>\r\n \t<li>An array to be sorted</li>\r\n \t<li>A closure that takes two arguments of the same type as the array and returns a true if the first value appears before the second value</li>\r\n</ul>\r\n<h2 id=\"tab2\" ><a name=\"_Toc39248511\"></a><a name=\"_Toc270097019\"></a>Using Swift functions as closures</h2>\r\nIn Swift, functions are special types of closures. As mentioned, the<code> sorted() </code>function needs a closure that takes two arguments of the same type as the array, returning a <code>true</code> if the first value appears before the second value. The following <a href=\"https://www.dummies.com/programming/macintosh/a-quick-intro-to-swift-functions/\" target=\"_blank\" rel=\"noopener\">Swift function</a> fulfils that requirement:\r\n<pre class=\"code\">func ascending(num1:Int, num2:Int) -> Bool {\r\n return num1</pre>\r\nThe <code>ascending()</code> function takes two arguments of type <code>Int</code> and returns a <code>Bool </code>value. If num1 is less than <code>num2</code>, it returns true. You can now pass this function to the <code>sorted()</code> function, as shown here:\r\n<pre class=\"code\">var sortedNumbers = numbers.sorted(by: ascending)</pre>\r\nThe <code>sorted()</code> function now returns the array that is sorted in ascending order.\r\n\r\nThe <code>sorted()</code> function does not modify the original array. It returns the sorted array as a new array.\r\n<h2 id=\"tab3\" ><a name=\"_Toc39248512\"></a><a name=\"_Toc270097020\"></a>Assigning Swift closures to variables</h2>\r\nAs mentioned earlier, functions are special types of closures. In fact, a closure is a function without a name. However, you can assign a closure to a variable — for example, the<code> ascending()</code> function discussed earlier can be written as a closure assigned to a variable:\r\n<pre class=\"code\">var compareClosure : (Int, Int)->Bool =\r\n {\r\n (num1:Int, num2:Int) -> Bool in\r\n return num1 < num2\r\n }</pre>\r\nTo use the <code>compareClosure</code> closure with the <code>sorted()</code> function, pass in the compareClosure variable:\r\n<pre class=\"code\">sortedNumbers = numbers.sorted(by: <strong>compareClosure</strong>)</pre>\r\n<h2 id=\"tab4\" ><a name=\"_Toc270097021\"></a><a name=\"_Toc39248513\"></a>Writing Swift closures inline</h2>\r\nYou can pass a function into the <code>sorted()</code> function as a closure function, but a better way is to write the closure inline, which obviates the need to define a function explicitly or assign it to a variable.\r\n\r\nRewriting the earlier example would yield the following:\r\n<pre class=\"code\">sortedNumbers = numbers.sorted(by:\r\n {\r\n (num1:Int, num2:Int) -> Bool in\r\n return num1 < num2\r\n }\r\n)</pre>\r\nAs you can see, the<code> ascending()</code> function name is now gone; all you’ve supplied is the parameter list and the content of the function.\r\n\r\nIf you want to sort the array in descending order, you can simply change the comparison operator:\r\n<pre class=\"code\">sortedNumbers = numbers.sorted(by:\r\n {\r\n (num1:Int, num2:Int) -> Bool in\r\n return num1 > num2\r\n }\r\n)</pre>\r\n<h2 id=\"tab5\" ><a name=\"_Toc270097022\"></a><a name=\"_Toc39248514\"></a>Understanding type inference</h2>\r\nBecause the type of the first argument of the closure function must be the same as the type of array you’re sorting, it’s actually redundant to specify the type in the closure, because the compiler can infer that from the type of array you’re using:\r\n<pre class=\"code\">var fruits = [\"orange\", \"apple\", \"durian\",\r\n \"rambutan\", \"pineapple\"]\r\nprint(fruits.sorted(by:\r\n {\r\n (fruit1, fruit2) in\r\n return fruit1</pre>\r\nIf your closure has only a single statement, you can even omit the<code> return </code>keyword:\r\n<pre class=\"code\">print(fruits.sorted(by:\r\n {\r\n (fruit1, fruit2) in\r\n fruit1</pre>\r\n<h2 id=\"tab6\" ><a name=\"_Toc270097023\"></a><a name=\"_Toc39248515\"></a>Using shorthand argument names</h2>\r\nAbove, names were given to arguments within a closure. In fact, this is also optional, because Swift automatically provides shorthand names to the parameters, which you can refer to as <code>$0</code>, <code>$1</code>, and so on.\r\n\r\nThe previous code snippet could be rewritten as follows without using named parameters:\r\n<pre class=\"code\">print(fruits.sorted(by:\r\n {\r\n $0<$1\r\n })\r\n)</pre>\r\nTo make the closure really terse, you can write everything on one line:\r\n\r\nprint(fruits.sorted(by:<strong>{ $0<$1 }</strong>))\r\n<h2 id=\"tab7\" ><a name=\"_Toc270097024\"></a><a name=\"_Toc39248516\"></a>Working with Swift’s operator function</h2>\r\nYou saw that the closure for the sorted() function was reduced to the following:\r\n<pre class=\"code\">print(fruits.sorted(by:{ $0<$1 }))</pre>\r\nOne of the implementations of the lesser than (<code><</code>) operator is actually a function that works with two operands of type <code>String</code>. Because of this, you can actually simply specify the <code><</code> operator in place of the closure, and the compiler will automatically infer that you want to use the particular implementation of the<code> </code><<code> operator. The preceding statement can be reduced to the following:</code>\r\n<pre class=\"code\">print(fruits.sorted(by:<strong><</strong>))</pre>\r\nIf you want to sort the array in descending order, simply use the greater than (>) operator:\r\n<pre class=\"code\">print(fruits.sorted(by:<strong>></strong>))</pre>\r\n<h2 id=\"tab8\" ><a name=\"_Toc39248517\"></a><a name=\"_Toc270097025\"></a>Using trailing closures in Swift</h2>\r\nConsider the closure that you saw earlier:\r\n<pre class=\"code\">print(fruits.sorted(by:\r\n {\r\n (fruit1, fruit2) in\r\n return fruit1</pre>\r\nNotice that the closure is passed in as a second argument of the <code>sorted()</code> function. For long closures, this syntax may be a little messy. If the closure is the final argument of a function, you can rewrite this closure as a trailing closure. A trailing closure is written outside of the parentheses of the function call. The preceding code snippet, when rewritten using the trailing closure, looks like this:\r\n<pre class=\"code\">print(fruits.sorted()\r\n {\r\n (fruit1, fruit2) in\r\n return fruit1</pre>\r\nUsing the shorthand argument name, the closure can be shortened to the following:\r\n<pre class=\"code\">print(fruits.sorted()<strong>{$0<$1}</strong>)</pre>\r\n \r\n\r\nWant to learn more? Check out our <a href=\"https://www.dummies.com/programming/macintosh/swift/swiftui-for-dummies-cheat-sheet/\" target=\"_blank\" rel=\"noopener\">SwiftUI Cheat Sheet</a>.","description":"One important feature in <a href=\"https://www.dummies.com/programming/macintosh/swift/what-is-swift-programming-understanding-what-swiftui-is/\" target=\"_blank\" rel=\"noopener\">Swift</a> is <em>closure</em><em>.</em> Closures are self-contained blocks of code that can be passed to functions to be executed as independent code units. Think of a closure as a function without a name. In fact, functions are actually special cases of closures.\r\n\r\n[caption id=\"attachment_274218\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-274218 size-full\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-developing-apps.jpg\" alt=\"SwiftUI app development \" width=\"556\" height=\"370\" /> ©Shutterstock/NDAB Creativity[/caption]\r\n\r\nSwift offers various ways to optimize closures so that they’re brief and succinct. The various optimizations include the following:\r\n<ul>\r\n \t<li>Inferring parameter types and return types</li>\r\n \t<li>Implicit returns from single-statement closures</li>\r\n \t<li>Shorthand argument names</li>\r\n \t<li>Trailing closure syntax</li>\r\n \t<li>Operator closure</li>\r\n</ul>\r\n<h2 id=\"tab1\" ><a name=\"_Toc39248510\"></a><a name=\"_Toc270097018\"></a>Understanding Swift closures</h2>\r\nThe best way to understand Swift closures is to use an example. Suppose you have the following array of integers:\r\n<pre class=\"code\">let numbers = [5,2,8,7,9,4,3,1]</pre>\r\nAssume you want to sort this array in ascending order. You could write your own function to perform the sorting, or you could use the <code>sorted()</code> function available in Swift. The<code> sorted()</code> function takes two arguments:\r\n<ul>\r\n \t<li>An array to be sorted</li>\r\n \t<li>A closure that takes two arguments of the same type as the array and returns a true if the first value appears before the second value</li>\r\n</ul>\r\n<h2 id=\"tab2\" ><a name=\"_Toc39248511\"></a><a name=\"_Toc270097019\"></a>Using Swift functions as closures</h2>\r\nIn Swift, functions are special types of closures. As mentioned, the<code> sorted() </code>function needs a closure that takes two arguments of the same type as the array, returning a <code>true</code> if the first value appears before the second value. The following <a href=\"https://www.dummies.com/programming/macintosh/a-quick-intro-to-swift-functions/\" target=\"_blank\" rel=\"noopener\">Swift function</a> fulfils that requirement:\r\n<pre class=\"code\">func ascending(num1:Int, num2:Int) -> Bool {\r\n return num1</pre>\r\nThe <code>ascending()</code> function takes two arguments of type <code>Int</code> and returns a <code>Bool </code>value. If num1 is less than <code>num2</code>, it returns true. You can now pass this function to the <code>sorted()</code> function, as shown here:\r\n<pre class=\"code\">var sortedNumbers = numbers.sorted(by: ascending)</pre>\r\nThe <code>sorted()</code> function now returns the array that is sorted in ascending order.\r\n\r\nThe <code>sorted()</code> function does not modify the original array. It returns the sorted array as a new array.\r\n<h2 id=\"tab3\" ><a name=\"_Toc39248512\"></a><a name=\"_Toc270097020\"></a>Assigning Swift closures to variables</h2>\r\nAs mentioned earlier, functions are special types of closures. In fact, a closure is a function without a name. However, you can assign a closure to a variable — for example, the<code> ascending()</code> function discussed earlier can be written as a closure assigned to a variable:\r\n<pre class=\"code\">var compareClosure : (Int, Int)->Bool =\r\n {\r\n (num1:Int, num2:Int) -> Bool in\r\n return num1 < num2\r\n }</pre>\r\nTo use the <code>compareClosure</code> closure with the <code>sorted()</code> function, pass in the compareClosure variable:\r\n<pre class=\"code\">sortedNumbers = numbers.sorted(by: <strong>compareClosure</strong>)</pre>\r\n<h2 id=\"tab4\" ><a name=\"_Toc270097021\"></a><a name=\"_Toc39248513\"></a>Writing Swift closures inline</h2>\r\nYou can pass a function into the <code>sorted()</code> function as a closure function, but a better way is to write the closure inline, which obviates the need to define a function explicitly or assign it to a variable.\r\n\r\nRewriting the earlier example would yield the following:\r\n<pre class=\"code\">sortedNumbers = numbers.sorted(by:\r\n {\r\n (num1:Int, num2:Int) -> Bool in\r\n return num1 < num2\r\n }\r\n)</pre>\r\nAs you can see, the<code> ascending()</code> function name is now gone; all you’ve supplied is the parameter list and the content of the function.\r\n\r\nIf you want to sort the array in descending order, you can simply change the comparison operator:\r\n<pre class=\"code\">sortedNumbers = numbers.sorted(by:\r\n {\r\n (num1:Int, num2:Int) -> Bool in\r\n return num1 > num2\r\n }\r\n)</pre>\r\n<h2 id=\"tab5\" ><a name=\"_Toc270097022\"></a><a name=\"_Toc39248514\"></a>Understanding type inference</h2>\r\nBecause the type of the first argument of the closure function must be the same as the type of array you’re sorting, it’s actually redundant to specify the type in the closure, because the compiler can infer that from the type of array you’re using:\r\n<pre class=\"code\">var fruits = [\"orange\", \"apple\", \"durian\",\r\n \"rambutan\", \"pineapple\"]\r\nprint(fruits.sorted(by:\r\n {\r\n (fruit1, fruit2) in\r\n return fruit1</pre>\r\nIf your closure has only a single statement, you can even omit the<code> return </code>keyword:\r\n<pre class=\"code\">print(fruits.sorted(by:\r\n {\r\n (fruit1, fruit2) in\r\n fruit1</pre>\r\n<h2 id=\"tab6\" ><a name=\"_Toc270097023\"></a><a name=\"_Toc39248515\"></a>Using shorthand argument names</h2>\r\nAbove, names were given to arguments within a closure. In fact, this is also optional, because Swift automatically provides shorthand names to the parameters, which you can refer to as <code>$0</code>, <code>$1</code>, and so on.\r\n\r\nThe previous code snippet could be rewritten as follows without using named parameters:\r\n<pre class=\"code\">print(fruits.sorted(by:\r\n {\r\n $0<$1\r\n })\r\n)</pre>\r\nTo make the closure really terse, you can write everything on one line:\r\n\r\nprint(fruits.sorted(by:<strong>{ $0<$1 }</strong>))\r\n<h2 id=\"tab7\" ><a name=\"_Toc270097024\"></a><a name=\"_Toc39248516\"></a>Working with Swift’s operator function</h2>\r\nYou saw that the closure for the sorted() function was reduced to the following:\r\n<pre class=\"code\">print(fruits.sorted(by:{ $0<$1 }))</pre>\r\nOne of the implementations of the lesser than (<code><</code>) operator is actually a function that works with two operands of type <code>String</code>. Because of this, you can actually simply specify the <code><</code> operator in place of the closure, and the compiler will automatically infer that you want to use the particular implementation of the<code> </code><<code> operator. The preceding statement can be reduced to the following:</code>\r\n<pre class=\"code\">print(fruits.sorted(by:<strong><</strong>))</pre>\r\nIf you want to sort the array in descending order, simply use the greater than (>) operator:\r\n<pre class=\"code\">print(fruits.sorted(by:<strong>></strong>))</pre>\r\n<h2 id=\"tab8\" ><a name=\"_Toc39248517\"></a><a name=\"_Toc270097025\"></a>Using trailing closures in Swift</h2>\r\nConsider the closure that you saw earlier:\r\n<pre class=\"code\">print(fruits.sorted(by:\r\n {\r\n (fruit1, fruit2) in\r\n return fruit1</pre>\r\nNotice that the closure is passed in as a second argument of the <code>sorted()</code> function. For long closures, this syntax may be a little messy. If the closure is the final argument of a function, you can rewrite this closure as a trailing closure. A trailing closure is written outside of the parentheses of the function call. The preceding code snippet, when rewritten using the trailing closure, looks like this:\r\n<pre class=\"code\">print(fruits.sorted()\r\n {\r\n (fruit1, fruit2) in\r\n return fruit1</pre>\r\nUsing the shorthand argument name, the closure can be shortened to the following:\r\n<pre class=\"code\">print(fruits.sorted()<strong>{$0<$1}</strong>)</pre>\r\n \r\n\r\nWant to learn more? Check out our <a href=\"https://www.dummies.com/programming/macintosh/swift/swiftui-for-dummies-cheat-sheet/\" target=\"_blank\" rel=\"noopener\">SwiftUI Cheat Sheet</a>.","blurb":"","authors":[{"authorId":33413,"name":"Wei-Meng Lee","slug":"wei-meng-lee","description":" <p><b>Wei-Meng Lee</b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p> ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33413"}}],"primaryCategoryTaxonomy":{"categoryId":33594,"title":"App Development","slug":"app-development","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33594"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":null,"inThisArticle":[{"label":"Understanding Swift closures","target":"#tab1"},{"label":"Using Swift functions as closures","target":"#tab2"},{"label":"Assigning Swift closures to variables","target":"#tab3"},{"label":"Writing Swift closures inline","target":"#tab4"},{"label":"Understanding type inference","target":"#tab5"},{"label":"Using shorthand argument names","target":"#tab6"},{"label":"Working with Swift’s operator function","target":"#tab7"},{"label":"Using trailing closures in Swift","target":"#tab8"}],"relatedArticles":{"fromBook":[{"articleId":274241,"title":"How to Make Your Own Animation in SwiftUI","slug":"how-to-make-your-own-animation-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274241"}},{"articleId":274231,"title":"Understanding How to Animate in SwiftUI","slug":"understanding-how-to-animate-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274231"}},{"articleId":274224,"title":"How to Use UIKit in SwiftUI","slug":"how-to-use-uikit-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274224"}},{"articleId":274211,"title":"A Quick Intro to Swift Functions","slug":"a-quick-intro-to-swift-functions","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274211"}},{"articleId":274206,"title":"10 Great SwiftUI Resources","slug":"10-great-swiftui-resources","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274206"}}],"fromCategory":[{"articleId":274241,"title":"How to Make Your Own Animation in SwiftUI","slug":"how-to-make-your-own-animation-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274241"}},{"articleId":274231,"title":"Understanding How to Animate in SwiftUI","slug":"understanding-how-to-animate-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274231"}},{"articleId":274224,"title":"How to Use UIKit in SwiftUI","slug":"how-to-use-uikit-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274224"}},{"articleId":274211,"title":"A Quick Intro to Swift Functions","slug":"a-quick-intro-to-swift-functions","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274211"}},{"articleId":274206,"title":"10 Great SwiftUI Resources","slug":"10-great-swiftui-resources","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274206"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281877,"slug":"swiftui-for-dummies","isbn":"9781119652687","categoryList":["technology","programming-web-design","app-development"],"amazon":{"default":"https://www.amazon.com/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119652685-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/swiftui-for-dummies-cover-9781119652687-203x255.jpg","width":203,"height":255},"title":"SwiftUI For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b><b data-author-id=\"33413\">Wei-Meng Lee</b></b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p>","authors":[{"authorId":33413,"name":"Wei-Meng Lee","slug":"wei-meng-lee","description":" <p><b>Wei-Meng Lee</b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p> ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33413"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;app-development&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119652687&quot;]}]\" id=\"du-slot-62f3f261bf87d\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;app-development&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119652687&quot;]}]\" id=\"du-slot-62f3f261c0144\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"One year","lifeExpectancySetFrom":"2022-08-10T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":274217},{"headers":{"creationTime":"2020-10-30T14:56:33+00:00","modifiedTime":"2022-08-10T16:33:19+00:00","timestamp":"2022-08-10T18:01:05+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Programming & Web Design","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33592"},"slug":"programming-web-design","categoryId":33592},{"name":"App Development","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33594"},"slug":"app-development","categoryId":33594}],"title":"Understanding How to Animate in SwiftUI","strippedTitle":"understanding how to animate in swiftui","slug":"understanding-how-to-animate-in-swiftui","canonicalUrl":"","seo":{"metaDescription":"SwiftUI makes easy work of animation. Use this brief guide to learn the basics of animating in SwiftUI, from Dummies.com.","noIndex":0,"noFollow":0},"content":"To animate a view in <a href=\"https://www.dummies.com/programming/macintosh/9-swiftui-tips-and-tricks/\" target=\"_blank\" rel=\"noopener\">SwiftUI</a>, apply the <code>animation()</code> modifier on it. SwiftUI animates any changes made to animatable properties of a view. For example, the various properties of a view in SwiftUI — such as its color, opacity, rotation, size, and other properties — are all animatable. As usual, the best way to understand this concept is to use an example.\r\n\r\nFirst, create a rounded button that shows the Confirm caption:\r\n<pre class=\"code\">struct ContentView: View {\r\n\r\n var body: some View {\r\n Button(action: {\r\n }) {\r\n Text(\"Confirm\")\r\n .bold()\r\n }\r\n .padding(40)\r\n .background(Color.green)\r\n .foregroundColor(.white)\r\n .clipShape(Circle())\r\n }\r\n}</pre>\r\n[caption id=\"attachment_274232\" align=\"aligncenter\" width=\"294\"]<img class=\"wp-image-274232 size-large\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-button-view-294x586.jpg\" alt=\"SwiftUI button view\" width=\"294\" height=\"586\" /> Displaying the rounded Button view in SwiftUI.[/caption]\r\n\r\n \r\n\r\nApply some scaling (zooming) to the button using the <code>scaleEffect()</code> modifier:\r\n<pre class=\"code\">struct ContentView: View {\r\n @State private var scaleFactor: CGFloat = 1\r\n\r\n var body: some View {\r\n Button(action: {\r\n }) {\r\n Text(\"Confirm\")\r\n .bold()\r\n }\r\n .onAppear(perform: {\r\n self.scaleFactor = 2.5\r\n })\r\n .padding(40)\r\n .background(Color.green)\r\n .foregroundColor(.white)\r\n .clipShape(Circle())\r\n .scaleEffect(scaleFactor)\r\n }\r\n}</pre>\r\nWhat you want to do here is zoom the button to two and a half times its original size. The scaling will be performed as soon as the <code>Button</code> view is shown in <a href=\"https://www.dummies.com/programming/macintosh/swift/swiftui-for-dummies-cheat-sheet/\" target=\"_blank\" rel=\"noopener\">SwiftUI</a>. The following image shows the button zoomed in to two and a half times its original size when it first appears.\r\n\r\n[caption id=\"attachment_274233\" align=\"aligncenter\" width=\"292\"]<img class=\"wp-image-274233 size-large\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-zoom-button-292x586.jpg\" alt=\"SwiftUI zoom button\" width=\"292\" height=\"586\" /> Zooming the Button view two and a half times in SwiftUI.[/caption]\r\n\r\n \r\n\r\nWhat you really want is to slow down the scaling, so that users can see the zooming-in process. For this, you can use the <code>animation()</code> modifier on the <code>Button</code> view:\r\n<pre class=\"code\">struct ContentView: View {\r\n @State private var scaleFactor: CGFloat = 1\r\n\r\n var body: some View {\r\n Button(action: {\r\n }) {\r\n Text(\"Confirm\")\r\n .bold()\r\n }\r\n .onAppear(perform: {\r\n self.scaleFactor = 2.5\r\n })\r\n .padding(40)\r\n .background(Color.green)\r\n .foregroundColor(.white)\r\n .clipShape(Circle())\r\n .scaleEffect(scaleFactor)\r\n .animation(.default)\r\n }\r\n}</pre>\r\nThe <code>.default</code> property actually belongs to the <code>Animation</code> struct, so you can rewrite the above statement as follows:\r\n<pre class=\"code\">.animation(<strong>Animation</strong>.default)</pre>\r\nWhen you now load the Button view again, the button zooms in two and a half times.\r\n<h2 id=\"tab1\" ><a name=\"_Toc33534804\"></a>Specifying the type of animation in SwiftUI</h2>\r\nBy default, the button will zoom in at a linear speed. You can also use the <code>easeInOur()</code> modifier if you want the animation to start slow, pick up speed, and then slow down again:\r\n<pre class=\"code\"> .animation(\r\n .easeInOut(duration: 2)\r\n )</pre>\r\nThe <code>duration</code> parameter indicates how much time is given for the animation to complete in SwiftUI. In this example, the zoom animation must complete in two seconds.\r\n\r\nIf you want to start fast and then slow down, use the <code>easeOut()</code> modifier:\r\n<pre class=\"code\"> .animation(\r\n .easeOut(duration: 2)\r\n )</pre>\r\nBoth the <code>easeInOut()</code> and <code>easeOut()</code> modifiers are type methods of the <code>Animation</code> struct.\r\n<h2 id=\"tab2\" ><a name=\"_Toc33534805\"></a>Repeating the animation in SwiftUI</h2>\r\nMany times, you want the animation to repeat a number of times. For this you can apply the repeatCount() modifier:\r\n<pre class=\"code\"> .animation(\r\n Animation.easeInOut(duration: 2)\r\n .repeatCount(2, autoreverses: true)\r\n )</pre>\r\nThe <code>easeInOut()</code> is a type method of the <code>Animation</code> struct, and it returns an <code>Animation</code> struct. So, in this case, you call the <code>repeatCount()</code> modifier of the <code>Animation</code> struct to repeat the animation a number of times (twice, in this case). The <code>autoreverses</code> parameter allows you to reverse the animation, so for this particular case the size of the button changes from small to big, and then reverses and changes from big to small.\r\n\r\nThe image below shows the animation that is repeated twice. Notice that at the end of the second animation, the button reverts back to the larger size as specified in the scaleFactor state variable:\r\n<pre class=\"code\">.scaleEffect(scaleFactor) // changed to 2.5 in onAppear()</pre>\r\n[caption id=\"attachment_274234\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-274234 size-full\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-scaling.png\" alt=\"animate button SwiftUI\" width=\"556\" height=\"231\" /> Animating the changing of the scale of the button.[/caption]\r\n\r\n \r\n\r\nIf you want the animation to repeat forever, use the <code>repeatForever()</code> modifier:\r\n<pre class=\"code\"> .animation(\r\n Animation.easeInOut(duration: 2)\r\n .repeatForever(autoreverses: true)\r\n )</pre>\r\n<h2 id=\"tab3\" ><a name=\"_Toc33534806\"></a>Stopping the animation in SwiftUI</h2>\r\nAlthough you can animate nonstop in SwiftUI, there are times where you need to stop the animation. Here’s another example:\r\n<pre class=\"code\">struct ContentView: View {\r\n @State private var opacity:Double = 1.0\r\n\r\n var body: some View {\r\n Button(action: {\r\n })\r\n {\r\n Text(\"Click Me\")\r\n .fontWeight(.bold)\r\n .font(.title)\r\n .foregroundColor(.blue)\r\n .padding()\r\n .background(Color.yellow)\r\n .overlay(\r\n Rectangle()\r\n .stroke(Color.blue, lineWidth: 5)\r\n )\r\n .opacity(opacity)\r\n .onAppear() {\r\n let baseAnimation =\r\n Animation.linear(duration: 1)\r\n withAnimation (\r\n baseAnimation.repeatForever(\r\n autoreverses: true))\r\n {\r\n self.opacity = 0.2\r\n }\r\n }\r\n }\r\n }\r\n}</pre>\r\nThe preceding code snippet shows a <code>Button</code> view with its opacity initially set to 1.0. When it appears, you perform a <em>linear animation</em> (animating with constant speed) to change the opacity of the button down to 0.2, all within a duration of 1 second. In the next 1 second, it then changes to fully opaque again.\r\n\r\nUnlike the earlier example, this example does not use the <code>animation()</code> modifier for animation. Instead, you use the <code>withAnimation</code> block. The <code>withAnimation</code> block lets you explicitly tell SwiftUI what to animate.\r\n\r\nThe image below shows the button fully opaque when it’s loaded and then gradually changes its opacity to 0.2.\r\n\r\n[caption id=\"attachment_274235\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-274235 size-full\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-dim-button-view.jpg\" alt=\"dim button view in SwiftUI\" width=\"556\" height=\"558\" /> Dimming the Button view in SwiftUI.[/caption]\r\n\r\n \r\n\r\nThe animation is perpetual, so to stop it, you need to do some work in SwiftUI. For this, you can use a Boolean state variable (let’s call it animate) and use it to determine if the animation should continue:\r\n<pre class=\"code\"> withAnimation (self.animate ?\r\n baseAnimation.repeatForever(\r\n autoreverses: true) :\r\n Animation.default) {\r\n self.opacity = 0.2\r\n }</pre>\r\nIn the preceding Swift code snippet, if the animate state variable is <code>true</code>, you’ll perform the animation perpetually, or you can set the animation to <code>default</code> (which will only perform the animation once).\r\n\r\nThe following code snippet stops the animation when the button is tapped and sets the opacity of the button back to 1:\r\n<pre class=\"code\">struct ContentView: View {\r\n @State private var opacity:Double = 1.0\r\n @State private var animate = true\r\n\r\n var body: some View {\r\n Button(action: {\r\n self.animate = false\r\n self.opacity = 1.0\r\n })\r\n {\r\n Text(\"Click Me\")\r\n .fontWeight(.bold)\r\n .font(.title)\r\n .foregroundColor(.blue)\r\n .padding()\r\n .background(Color.yellow)\r\n .overlay(\r\n Rectangle()\r\n .stroke(Color.blue, lineWidth: 5)\r\n )\r\n .opacity(opacity)\r\n .onAppear() {\r\n let baseAnimation =\r\n Animation.linear(duration: 1)\r\n withAnimation (self.animate ?\r\n baseAnimation.repeatForever(\r\n autoreverses: true) :\r\n Animation.default) {\r\n self.opacity = 0.2\r\n }\r\n }\r\n }\r\n }\r\n}</pre>\r\nRemember to follow the <a href=\"https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/animation\" target=\"_blank\" rel=\"noopener\">Apple Human Interface Guidelines (HIG)</a> when it comes to animating your UI. This also applies to custom animations.\r\n\r\nWant to learn more? Check out these <a href=\"https://www.dummies.com/programming/macintosh/10-great-swiftui-resources/\" target=\"_blank\" rel=\"noopener\">SwiftUI resources</a>.","description":"To animate a view in <a href=\"https://www.dummies.com/programming/macintosh/9-swiftui-tips-and-tricks/\" target=\"_blank\" rel=\"noopener\">SwiftUI</a>, apply the <code>animation()</code> modifier on it. SwiftUI animates any changes made to animatable properties of a view. For example, the various properties of a view in SwiftUI — such as its color, opacity, rotation, size, and other properties — are all animatable. As usual, the best way to understand this concept is to use an example.\r\n\r\nFirst, create a rounded button that shows the Confirm caption:\r\n<pre class=\"code\">struct ContentView: View {\r\n\r\n var body: some View {\r\n Button(action: {\r\n }) {\r\n Text(\"Confirm\")\r\n .bold()\r\n }\r\n .padding(40)\r\n .background(Color.green)\r\n .foregroundColor(.white)\r\n .clipShape(Circle())\r\n }\r\n}</pre>\r\n[caption id=\"attachment_274232\" align=\"aligncenter\" width=\"294\"]<img class=\"wp-image-274232 size-large\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-button-view-294x586.jpg\" alt=\"SwiftUI button view\" width=\"294\" height=\"586\" /> Displaying the rounded Button view in SwiftUI.[/caption]\r\n\r\n \r\n\r\nApply some scaling (zooming) to the button using the <code>scaleEffect()</code> modifier:\r\n<pre class=\"code\">struct ContentView: View {\r\n @State private var scaleFactor: CGFloat = 1\r\n\r\n var body: some View {\r\n Button(action: {\r\n }) {\r\n Text(\"Confirm\")\r\n .bold()\r\n }\r\n .onAppear(perform: {\r\n self.scaleFactor = 2.5\r\n })\r\n .padding(40)\r\n .background(Color.green)\r\n .foregroundColor(.white)\r\n .clipShape(Circle())\r\n .scaleEffect(scaleFactor)\r\n }\r\n}</pre>\r\nWhat you want to do here is zoom the button to two and a half times its original size. The scaling will be performed as soon as the <code>Button</code> view is shown in <a href=\"https://www.dummies.com/programming/macintosh/swift/swiftui-for-dummies-cheat-sheet/\" target=\"_blank\" rel=\"noopener\">SwiftUI</a>. The following image shows the button zoomed in to two and a half times its original size when it first appears.\r\n\r\n[caption id=\"attachment_274233\" align=\"aligncenter\" width=\"292\"]<img class=\"wp-image-274233 size-large\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-zoom-button-292x586.jpg\" alt=\"SwiftUI zoom button\" width=\"292\" height=\"586\" /> Zooming the Button view two and a half times in SwiftUI.[/caption]\r\n\r\n \r\n\r\nWhat you really want is to slow down the scaling, so that users can see the zooming-in process. For this, you can use the <code>animation()</code> modifier on the <code>Button</code> view:\r\n<pre class=\"code\">struct ContentView: View {\r\n @State private var scaleFactor: CGFloat = 1\r\n\r\n var body: some View {\r\n Button(action: {\r\n }) {\r\n Text(\"Confirm\")\r\n .bold()\r\n }\r\n .onAppear(perform: {\r\n self.scaleFactor = 2.5\r\n })\r\n .padding(40)\r\n .background(Color.green)\r\n .foregroundColor(.white)\r\n .clipShape(Circle())\r\n .scaleEffect(scaleFactor)\r\n .animation(.default)\r\n }\r\n}</pre>\r\nThe <code>.default</code> property actually belongs to the <code>Animation</code> struct, so you can rewrite the above statement as follows:\r\n<pre class=\"code\">.animation(<strong>Animation</strong>.default)</pre>\r\nWhen you now load the Button view again, the button zooms in two and a half times.\r\n<h2 id=\"tab1\" ><a name=\"_Toc33534804\"></a>Specifying the type of animation in SwiftUI</h2>\r\nBy default, the button will zoom in at a linear speed. You can also use the <code>easeInOur()</code> modifier if you want the animation to start slow, pick up speed, and then slow down again:\r\n<pre class=\"code\"> .animation(\r\n .easeInOut(duration: 2)\r\n )</pre>\r\nThe <code>duration</code> parameter indicates how much time is given for the animation to complete in SwiftUI. In this example, the zoom animation must complete in two seconds.\r\n\r\nIf you want to start fast and then slow down, use the <code>easeOut()</code> modifier:\r\n<pre class=\"code\"> .animation(\r\n .easeOut(duration: 2)\r\n )</pre>\r\nBoth the <code>easeInOut()</code> and <code>easeOut()</code> modifiers are type methods of the <code>Animation</code> struct.\r\n<h2 id=\"tab2\" ><a name=\"_Toc33534805\"></a>Repeating the animation in SwiftUI</h2>\r\nMany times, you want the animation to repeat a number of times. For this you can apply the repeatCount() modifier:\r\n<pre class=\"code\"> .animation(\r\n Animation.easeInOut(duration: 2)\r\n .repeatCount(2, autoreverses: true)\r\n )</pre>\r\nThe <code>easeInOut()</code> is a type method of the <code>Animation</code> struct, and it returns an <code>Animation</code> struct. So, in this case, you call the <code>repeatCount()</code> modifier of the <code>Animation</code> struct to repeat the animation a number of times (twice, in this case). The <code>autoreverses</code> parameter allows you to reverse the animation, so for this particular case the size of the button changes from small to big, and then reverses and changes from big to small.\r\n\r\nThe image below shows the animation that is repeated twice. Notice that at the end of the second animation, the button reverts back to the larger size as specified in the scaleFactor state variable:\r\n<pre class=\"code\">.scaleEffect(scaleFactor) // changed to 2.5 in onAppear()</pre>\r\n[caption id=\"attachment_274234\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-274234 size-full\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-scaling.png\" alt=\"animate button SwiftUI\" width=\"556\" height=\"231\" /> Animating the changing of the scale of the button.[/caption]\r\n\r\n \r\n\r\nIf you want the animation to repeat forever, use the <code>repeatForever()</code> modifier:\r\n<pre class=\"code\"> .animation(\r\n Animation.easeInOut(duration: 2)\r\n .repeatForever(autoreverses: true)\r\n )</pre>\r\n<h2 id=\"tab3\" ><a name=\"_Toc33534806\"></a>Stopping the animation in SwiftUI</h2>\r\nAlthough you can animate nonstop in SwiftUI, there are times where you need to stop the animation. Here’s another example:\r\n<pre class=\"code\">struct ContentView: View {\r\n @State private var opacity:Double = 1.0\r\n\r\n var body: some View {\r\n Button(action: {\r\n })\r\n {\r\n Text(\"Click Me\")\r\n .fontWeight(.bold)\r\n .font(.title)\r\n .foregroundColor(.blue)\r\n .padding()\r\n .background(Color.yellow)\r\n .overlay(\r\n Rectangle()\r\n .stroke(Color.blue, lineWidth: 5)\r\n )\r\n .opacity(opacity)\r\n .onAppear() {\r\n let baseAnimation =\r\n Animation.linear(duration: 1)\r\n withAnimation (\r\n baseAnimation.repeatForever(\r\n autoreverses: true))\r\n {\r\n self.opacity = 0.2\r\n }\r\n }\r\n }\r\n }\r\n}</pre>\r\nThe preceding code snippet shows a <code>Button</code> view with its opacity initially set to 1.0. When it appears, you perform a <em>linear animation</em> (animating with constant speed) to change the opacity of the button down to 0.2, all within a duration of 1 second. In the next 1 second, it then changes to fully opaque again.\r\n\r\nUnlike the earlier example, this example does not use the <code>animation()</code> modifier for animation. Instead, you use the <code>withAnimation</code> block. The <code>withAnimation</code> block lets you explicitly tell SwiftUI what to animate.\r\n\r\nThe image below shows the button fully opaque when it’s loaded and then gradually changes its opacity to 0.2.\r\n\r\n[caption id=\"attachment_274235\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-274235 size-full\" src=\"https://www.dummies.com/wp-content/uploads/swiftui-dim-button-view.jpg\" alt=\"dim button view in SwiftUI\" width=\"556\" height=\"558\" /> Dimming the Button view in SwiftUI.[/caption]\r\n\r\n \r\n\r\nThe animation is perpetual, so to stop it, you need to do some work in SwiftUI. For this, you can use a Boolean state variable (let’s call it animate) and use it to determine if the animation should continue:\r\n<pre class=\"code\"> withAnimation (self.animate ?\r\n baseAnimation.repeatForever(\r\n autoreverses: true) :\r\n Animation.default) {\r\n self.opacity = 0.2\r\n }</pre>\r\nIn the preceding Swift code snippet, if the animate state variable is <code>true</code>, you’ll perform the animation perpetually, or you can set the animation to <code>default</code> (which will only perform the animation once).\r\n\r\nThe following code snippet stops the animation when the button is tapped and sets the opacity of the button back to 1:\r\n<pre class=\"code\">struct ContentView: View {\r\n @State private var opacity:Double = 1.0\r\n @State private var animate = true\r\n\r\n var body: some View {\r\n Button(action: {\r\n self.animate = false\r\n self.opacity = 1.0\r\n })\r\n {\r\n Text(\"Click Me\")\r\n .fontWeight(.bold)\r\n .font(.title)\r\n .foregroundColor(.blue)\r\n .padding()\r\n .background(Color.yellow)\r\n .overlay(\r\n Rectangle()\r\n .stroke(Color.blue, lineWidth: 5)\r\n )\r\n .opacity(opacity)\r\n .onAppear() {\r\n let baseAnimation =\r\n Animation.linear(duration: 1)\r\n withAnimation (self.animate ?\r\n baseAnimation.repeatForever(\r\n autoreverses: true) :\r\n Animation.default) {\r\n self.opacity = 0.2\r\n }\r\n }\r\n }\r\n }\r\n}</pre>\r\nRemember to follow the <a href=\"https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/animation\" target=\"_blank\" rel=\"noopener\">Apple Human Interface Guidelines (HIG)</a> when it comes to animating your UI. This also applies to custom animations.\r\n\r\nWant to learn more? Check out these <a href=\"https://www.dummies.com/programming/macintosh/10-great-swiftui-resources/\" target=\"_blank\" rel=\"noopener\">SwiftUI resources</a>.","blurb":"","authors":[{"authorId":33413,"name":"Wei-Meng Lee","slug":"wei-meng-lee","description":" <p><b>Wei-Meng Lee</b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p> ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33413"}}],"primaryCategoryTaxonomy":{"categoryId":33594,"title":"App Development","slug":"app-development","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33594"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":null,"inThisArticle":[{"label":"Specifying the type of animation in SwiftUI","target":"#tab1"},{"label":"Repeating the animation in SwiftUI","target":"#tab2"},{"label":"Stopping the animation in SwiftUI","target":"#tab3"}],"relatedArticles":{"fromBook":[{"articleId":274241,"title":"How to Make Your Own Animation in SwiftUI","slug":"how-to-make-your-own-animation-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274241"}},{"articleId":274224,"title":"How to Use UIKit in SwiftUI","slug":"how-to-use-uikit-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274224"}},{"articleId":274217,"title":"Swift Closures","slug":"swift-closures","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274217"}},{"articleId":274211,"title":"A Quick Intro to Swift Functions","slug":"a-quick-intro-to-swift-functions","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274211"}},{"articleId":274206,"title":"10 Great SwiftUI Resources","slug":"10-great-swiftui-resources","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274206"}}],"fromCategory":[{"articleId":274241,"title":"How to Make Your Own Animation in SwiftUI","slug":"how-to-make-your-own-animation-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274241"}},{"articleId":274224,"title":"How to Use UIKit in SwiftUI","slug":"how-to-use-uikit-in-swiftui","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274224"}},{"articleId":274217,"title":"Swift Closures","slug":"swift-closures","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274217"}},{"articleId":274211,"title":"A Quick Intro to Swift Functions","slug":"a-quick-intro-to-swift-functions","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274211"}},{"articleId":274206,"title":"10 Great SwiftUI Resources","slug":"10-great-swiftui-resources","categoryList":["technology","programming-web-design","app-development"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/274206"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281877,"slug":"swiftui-for-dummies","isbn":"9781119652687","categoryList":["technology","programming-web-design","app-development"],"amazon":{"default":"https://www.amazon.com/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119652685-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119652685/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/swiftui-for-dummies-cover-9781119652687-203x255.jpg","width":203,"height":255},"title":"SwiftUI For Dummies","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><b><b data-author-id=\"33413\">Wei-Meng Lee</b></b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p>","authors":[{"authorId":33413,"name":"Wei-Meng Lee","slug":"wei-meng-lee","description":" <p><b>Wei-Meng Lee</b> is founder of Developer Learning Solutions, specializing in hands-on technology training. His name regularly appears in publications like DevX.com, MobiForge.com, and <i>CODE Magazine</i>. He is also the author of <i>SwiftUI For Dummies, Beginning Swift Programming, Python Machine Learning,</i> and <i>Learning WatchKit Programming</i>.</p> ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33413"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;app-development&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119652687&quot;]}]\" id=\"du-slot-62f3f261b77b2\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;programming-web-design&quot;,&quot;app-development&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119652687&quot;]}]\" id=\"du-slot-62f3f261b8074\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"One year","lifeExpectancySetFrom":"2022-08-10T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":274231},{"headers":{"creationTime":"2020-09-30T18:28:21+00:00","modifiedTime":"2022-08-10T16:29:52+00:00","timestamp":"2022-08-10T18:01:05+00:00"},"data":{"breadcrumbs":[{"name":"Technology","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33512"},"slug":"technology","categoryId":33512},{"name":"Software","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33618"},"slug":"software","categoryId":33618},{"name":"Design Software","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33634"},"slug":"design-software","categoryId":33634},{"name":"SketchUp","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33636"},"slug":"sketchup","categoryId":33636}],"title":"10 SketchUp Issues and Their Workarounds","strippedTitle":"10 sketchup issues and their workarounds","slug":"10-sketchup-issues-and-their-workarounds","canonicalUrl":"","seo":{"metaDescription":"Like any software, SketchUp is bound to have its problems. Use this guide to discover ten common problems and their solutions.","noIndex":0,"noFollow":0},"content":"The bad news is that every new SketchUp user encounters certain problems, usually in the first couple hours of using the software. You can call these problems growing pains. The good news is that, because these SketchUp problems are common, you can anticipate a lot of the bad stuff you’ll go through. This article offers you SketchUp tips and tricks to help you work around those issues.\r\n<h2 id=\"tab1\" >SketchUp won’t create a face where you want it to</h2>\r\nYou’ve dutifully traced all around where you want <a href=\"https://www.dummies.com/programming/google-sketchup/how-to-paint-faces-in-sketchup-with-color-and-texture/\" target=\"_blank\" rel=\"noopener\">SketchUp to create a face</a>, but nothing’s happening. If you follow along in the image below, which was inspired by a visit to the M.C. Escher museum in Amsterdam, you see the top-left image seems to show a cube beside a rectangle, but the rectangle didn’t produce a face. In the top-right image, a diagonal line was drawn between diagonally opposite corners of the rectangle, producing two triangular faces, but something still doesn’t look right.\r\n\r\nChanging the camera position to standard front (lower-left image) and right side (lower-right image) reveals the source of the problem. It turns out that the upper-right corner of the rectangle doesn’t lie on the red-blue plane but is actually to the right of the blue-green plane, and to the right of the blue-red plane. The upper-left image isn’t really an optical illusion; it just looks like one.\r\n\r\n[caption id=\"attachment_273641\" align=\"aligncenter\" width=\"509\"]<img class=\"wp-image-273641 size-large\" src=\"https://www.dummies.com/wp-content/uploads/sketchup-problems-509x586.jpg\" alt=\"SketchUp problems \" width=\"509\" height=\"586\" /> Just because it looks right doesn’t mean that it is.[/caption]\r\n\r\nNinety percent of the time, when SketchUp doesn’t create a face where you think it should, an edge isn’t on the plane you think it’s on. To check whether your edges are coplanar, draw an edge that cuts diagonally across the area where you want a face to appear. If a face appears now, your edges aren’t all on the same plane. To fix the problem, you have to figure out which edge is the culprit, and the Color By Axis option may help you see this information at a glance. Here’s how Color By Axis works:\r\n<ol>\r\n \t<li>In the Styles panel, change your edge color from All Same to By Axis.SketchUp draws the edges in your model using the color of the axis to which they’re parallel; edges parallel to the red axis are red, and so on.</li>\r\n \t<li>Look carefully at the edges that you wanted to define your desired face.Are all the edges the color they’re supposed to be? If they’re not all supposed to be parallel to the drawing axes, this technique doesn’t do much good. But if they are, and one (or more) of them is black (instead of red or green or blue), that edge (or those edges) is your problem child. Fix it and switch back to All Same when you’re done.</li>\r\n</ol>\r\nIf the plane isn’t the problem with your edges, then check whether one edge is part of a separate group or component. To check whether you have a component problem, try hiding groups or components and checking the edges to make sure that they’re all in the group or component you think they’re in.\r\n<p class=\"article-tips tip\">A common source of this problem is <a href=\"https://www.dummies.com/programming/google-sketchup/sketchups-inferences/\" target=\"_blank\" rel=\"noopener\">SketchUp’s inferences</a>. As you slide the mouse over a face you may unwittingly be latching on to an unintended inference, such as the edge of a surface that is part of a cylinder. Watch those inference prompts, and use Undo when you complete a face but no face appears.</p>\r\n\r\n<h2 id=\"tab2\" >Your SketchUp faces are two different colors</h2>\r\nIn SketchUp, faces have two sides: a front and a back. By default, these two sides are different colors.\r\n\r\nWhen you use certain tools, such as Push/Pull or Follow Me, on a face, sometimes the faces on the resulting geometry are “inside out.” For some people, the issue is just bothersome. If you want to 3D-print your model, you need to fix the issue so that your model will print correctly.\r\n\r\nTo fix this issue, right-click the faces you want to flip and choose Reverse Faces from the context menu. If you have lots of faces to flip, you can select them all and then choose Reverse Faces to flip them all at once.\r\n\r\nIn 3D printing, this process is called checking your model’s normals.\r\n\r\nThe plan for the structure you see below was for all the outside walls to be wood siding and the interior walls to be painted yellow. But the top two images show that somehow the left wall got reversed. The bottom two images show that the problem has been solved by selecting the yellow face and reversing it.\r\n\r\n[caption id=\"attachment_273642\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-273642 size-full\" src=\"https://www.dummies.com/wp-content/uploads/sketchup-face.jpg\" alt=\"reverse SketchUp faces\" width=\"556\" height=\"476\" /> Reversing the faces in SketchUp.[/caption]\r\n<h2 id=\"tab3\" >Edges on a face won’t sink in</h2>\r\nEdges on a face tend not to sink in when you’re trying to draw a rectangle (or another geometric figure) on a face with one of SketchUp’s shape-drawing tools. Ordinarily, the Rectangle tool creates a new face on top of any face you use it on; after that, you can use Push/Pull to create a hole, if you want.\r\n\r\nWhen the edges you just drew don’t seem to cut through the face you drew them on, try these approaches:\r\n<ul>\r\n \t<li><strong>Retrace one of the edges.</strong> Sometimes that works — you’d be surprised how often.</li>\r\n \t<li><strong>Select Hidden Geometry from the View menu.</strong> You’re checking to make sure that the face you just drew isn’t crossing any hidden or smoothed edges; if it is, the face you thought was flat may not be.</li>\r\n \t<li><strong>Make sure that the face you drew on isn’t part of a group or component.</strong> If it is, undo a few steps and then redraw your shape while you edit the group or component.</li>\r\n \t<li><strong>Select the face + edges, right-click, and choose Intersect Faces→With Selection. </strong>This approach is often needed when you are working with one or more curved surfaces.</li>\r\n</ul>\r\n<h2 id=\"tab4\" >SketchUp crashed, and you lost your model</h2>\r\nUnfortunately, SketchUp crashes happen sometimes. The good news is that SketchUp automatically saves a copy of your file every five minutes.\r\n\r\nIn the web version, these autosaves are captured in Trimble Connect as revisions. You can always view the revision history for a file by navigating to it in the Trimble Connect tab (by clicking Open in the menu at the top of the screen to access Trimble Connect). For any file, you can choose to view or restore an older version.\r\n\r\nIn desktop versions, the file that SketchUp autosaves is actually a <em>separate</em> file, <em>AutoSave_yourfilename.skp</em>. If your file ever gets corrupted in a crash, an intact file is ready for you.\r\n\r\nThe problem is that most people don’t even know that the autosaved file is there. Where do you find it? If you’ve ever saved your file, the autosaved file is in the same folder as the original; therefore, it’s very important that you save your file almost immediately after starting it.\r\n<p class=\"article-tips tech\">Simple, right? Not so fast. On a Mac, you may need to change your Library folder from hidden to visible. In the Finder app, hold down the Option key while you choose Go→Library. If you don’t hold down the Option key, Library may not appear on the menu.</p>\r\nWhen you close your model, SketchUp typically assumes nothing untoward has happened and usually cleans up after itself by deleting the autosaved file.\r\n<p class=\"article-tips tip\">The really good news is that every time you save a file, SketchUp proactively saves two identical files, one with the normal file extension .SKP and the other with the file extension .SKB. You continue working on the .SKP file. If something goes really wrong with your model, you can always go back to how it was an instant before the last time you saved it. But you can’t find it in the Open File dialog box. Here’s the secret: In the Open File dialog box, go to the end of the File Name window, click the down arrow beside Sketchup Models (.SKP), and click All Files. Now the .SKB files show, and you can open them. (web: The same basic principles apply, but read more details on <a href=\"https://help.sketchup.com/en/sketchup-web/saving-opening-and-downloading-models\" target=\"_blank\" rel=\"noopener\">SketchUp's website</a>.)</p>\r\nTo minimize the amount of work you lose when software (or hardware) goes south, always do two things:\r\n<ul>\r\n \t<li>Save often — compulsively, even.</li>\r\n \t<li>Use the Save a Copy As command on the File menu.</li>\r\n</ul>\r\nWhen you’re working on a big project, the following steps can help ensure you don’t lose any work:\r\n<ol>\r\n \t<li>Save the original version of your file as <em>yourfilename_Master.skp</em>.That’s the file you’ll always be working on.</li>\r\n \t<li>Create a folder that lives in the same place as your Master file; call the folder something like <em>Your file’s name</em> Archive<strong>.</strong></li>\r\n \t<li>Every half-hour or so, choose File→Save a Copy As, and save a sequentially numbered version of your file to the Archive folder.When you’re building a big model, it’s not uncommon for your Archive folder to contain 40 or 50 saved versions of the model dating back to when the project first started.</li>\r\n \t<li>Back up regularly.At least at the end of every work session, such as when you head to a coffee or lunch break, back up your files to a low-cost, high-capacity, high-speed portable USB drive, then remove it and keep it separate from your computer. At the end of your shift, take it to a different location. You don’t need to keep it in a bank vault, just in a separate building. Take it home at night, for example.\r\n<p class=\"article-tips remember\">You can always buy new hardware and software, but you can’t buy your personal files.</p>\r\n</li>\r\n</ol>\r\n<h2 id=\"tab5\" >SketchUp is sooooo slooooooooow</h2>\r\nThe bigger your SketchUp model, the worse your computer’s performance. What makes a model big? In a nutshell, faces.\r\n\r\nDo everything in your power to keep your model as small as you can. Here are some tips for doing that:\r\n<ul>\r\n \t<li><strong>Reduce the number of sides on your extruded circles and arcs.</strong></li>\r\n \t<li><strong>Use 2D people and trees instead of 3D ones.</strong> 3D plants and people have hundreds of faces each. Consider using 2D ones instead, especially if your model won’t be seen much from overhead.</li>\r\n \t<li><strong>Use search filters in 3D Warehouse.</strong> When you’re searching for models in <a href=\"https://www.dummies.com/programming/google-sketchup/working-with-sketchups-3d-warehouse/\" target=\"_blank\" rel=\"noopener\">3D Warehouse</a>, you can restrict your search result to show only models of a certain file size or polygon (face) complexity. Especially if your model is more than 10 MB, it makes sense to keep your 3D Warehouse downloads small!</li>\r\n</ul>\r\nSome models are just big, and you can’t do much about it. Here are some tricks for working with very large SketchUp models:\r\n<ul>\r\n \t<li><strong>Make liberal use of the Outliner and tags.</strong> These SketchUp features were specifically designed to let you organize your model into manageable chunks. Hide everything you’re not working on at the moment; doing so gives your computer a fighting chance.</li>\r\n \t<li><strong>Substitute simple forms for large numbers of complex components.</strong> For example, insert sticks as placeholders for big sets of 3D trees, cars, and other big components.</li>\r\n \t<li><strong>Turn off shadows and switch to a simple style, such as Shaded in the Default Styles collection.</strong> It takes a lot of computer horsepower to display shadows, edge effects, and textures in real time on your monitor. When you’re working, turn off all that stuff.</li>\r\n \t<li><strong>Use scenes to navigate between views.</strong> Scenes aren’t just for presenting your model; they’re also great for working with it. If you create scenes for the different views you commonly use and with different combinations of hidden geometry, then you don’t have to orbit, pan, and zoom around your gigantic model. To speed up things even more, deselect Enable Scene Transitions in the Animation panel of the Model Info dialog box. (web: Animation settings are in the Scenes panel.)</li>\r\n</ul>\r\n<h2 id=\"tab6\" >You can’t get a good view of the inside of your SketchUp model</h2>\r\nIt’s not always easy to work on the inside of something in SketchUp. You can do these things to make it easier, though:\r\n<ul>\r\n \t<li><strong>Cut into your model with section</strong> SketchUp’s Sections feature lets you cut away parts of your model — temporarily, of course — so that you can get a better view of what’s inside.</li>\r\n \t<li><strong>Widen your field of view. </strong><em>Field of view</em> is the part of your model you can see onscreen at one time. A wider FOV is like having better peripheral vision.</li>\r\n</ul>\r\n<p class=\"article-tips tip\">You can change the field of view only when in Perspective view mode, but the setting will be remembered if you then switch to Parallel view mode.</p>\r\nThe image below shows the plan view of a room. If you zoom or walk in through the door — oops, tunnel vision. Increase peripheral vision by changing your <a href=\"https://www.dummies.com/programming/google-sketchup/how-to-set-your-field-of-view-in-google-sketchup-8/\" target=\"_blank\" rel=\"noopener\">field of view</a>. Ah, that’s better! Now you can see that the picture hanging on the wall is the floor plan of this room.\r\n\r\n[caption id=\"attachment_273643\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-273643 size-full\" src=\"https://www.dummies.com/wp-content/uploads/sketchup-field-of-view.jpg\" alt=\"SketchUp field of view\" width=\"556\" height=\"316\" /> Changing SketchUp's field of view makes a world of difference.[/caption]\r\n<h2 id=\"tab7\" >A face flashes when you orbit in SketchUp</h2>\r\nIf you have two faces in the same spot — maybe one is in a separate group or component — you see a <em>Z-fighting</em> effect. SketchUp is deciding which face to display by switching back and forth between them; it’s not a good solution, but certainly a logical one — at least for a piece of software. The image below attempts to portray this effect in a single image. The only way to get rid of Z-fighting is to delete or hide one of the faces.\r\n\r\n[caption id=\"attachment_273644\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-273644 size-full\" src=\"https://www.dummies.com/wp-content/uploads/sketchup-faces.jpg\" alt=\"SketchUp face flashing\" width=\"556\" height=\"308\" /> Two faces fighting for the same 3D real estate.[/caption]\r\n<h2 id=\"tab8\" >You can’t move your SketchUp component the way you want</h2>\r\nWhen you insert some components into your model, the components by default glue to faces. A glued component instance isn’t actually glued in one place. Instead, it’s glued to the plane of the face you originally placed (or created) it on. For example, if you place a sofa component on the floor of your living room, you can move it around only on that plane — not up and down.\r\n\r\nThis gluing behavior comes in handy when you deal with things like furniture; it allows you to rearrange things with the Move tool without accidentally picking them up.\r\n\r\nIf you can’t move your component the way you want to, right-click it to see whether Unglue is an option; if it is, choose it. Now you can move your component around however you want.\r\n<h2 id=\"tab9\" >Bad stuff happens almost every time you use SketchUp’s Eraser</h2>\r\nWhen you use the Eraser tool, it’s pretty easy to delete stuff accidentally. Worse, you usually don’t notice what’s missing until it’s too late. Here are some tips for erasing more accurately:\r\n<ul>\r\n \t<li><strong>Orbit around.</strong> Try to make sure that nothing is behind whatever you’re erasing; use SketchUp’s navigation tools to get a view of your model that puts you out of danger.</li>\r\n \t<li><strong>Switch on Back Edges.</strong> When you’re doing a lot of erasing, choose View→Edge Style→Back Edges. That way, you can see every edge in your model, and you’re less likely to erase the wrong ones.</li>\r\n \t<li><strong>Use the Undo modifier of the eraser. </strong>Follow along starting in the upper-left image you see below. The intent is to erase the four edges in the center to create a single face. While erasing, you can select multiple objects by holding down the left mouse button while dragging the eraser over them. Oh, great googly moogly (or words to that effect) — you selected some things you didn’t want to erase. No problem: <em>Don’t</em> release the mouse button, but press and hold down the keyboard Alt key (Mac: <strong>⌘</strong>). Now anything you drag the eraser over will be unselected. You can switch back and forth as desired, but nothing actually gets erased until you release the mouse button.</li>\r\n \t<li><strong>Double-check.</strong> After you do a lot of erasing, give your model a quick once-over with the Orbit tool, just to make sure that you didn’t get rid of anything important. Put a sticky note on your computer monitor that says something like <em>Check after Erase!</em> just to remind you.</li>\r\n</ul>\r\n[caption id=\"attachment_273645\" align=\"aligncenter\" width=\"442\"]<img class=\"wp-image-273645 size-large\" src=\"https://www.dummies.com/wp-content/uploads/sketchup-uneraser-442x586.jpg\" alt=\"SketchUp uneraser\" width=\"442\" height=\"586\" /> The uneraser in action.[/caption]\r\n<h2 id=\"tab10\" >All your edges and faces have different tags</h2>\r\nUsing Tags in SketchUp can be a dangerous business. Here’s the short version of some good advice: Always build everything on Untagged, and assign whole groups or components to other tags only if you really need to.\r\n\r\nIf you used tags in SketchUp and now things are messed up, here’s what you can do to recover:\r\n<ol>\r\n \t<li>Make sure that everything is visible.Select Hidden Geometry on the View menu; then (in the Tags panel) make all your tags visible. Just make sure that you can see everything in your model.</li>\r\n \t<li>Choose Edit→Select All.</li>\r\n \t<li>In the Entity Info panel, move everything to Layer0.</li>\r\n \t<li>In the Tags panel, delete your other tags.</li>\r\n \t<li>When you’re prompted, tell SketchUp to move anything remaining on them to Untagged.</li>\r\n \t<li>Create new tags and follow best practices to avoid problems.</li>\r\n</ol>\r\n<p class=\"article-tips tip\">If you’ve downloaded 3D Warehouse models, you’ll probably find that they have some tags that you don’t understand and might want to get rid of. They may have had significance to the original creator, but they can become clutter in your file, so they should be removed.</p>\r\nWant to learn more? Check out our <a href=\"https://www.dummies.com/programming/google-sketchup/sketchup-for-dummies-cheat-sheet/\" target=\"_blank\" rel=\"noopener\">SketchUp Cheat Sheet</a>.","description":"The bad news is that every new SketchUp user encounters certain problems, usually in the first couple hours of using the software. You can call these problems growing pains. The good news is that, because these SketchUp problems are common, you can anticipate a lot of the bad stuff you’ll go through. This article offers you SketchUp tips and tricks to help you work around those issues.\r\n<h2 id=\"tab1\" >SketchUp won’t create a face where you want it to</h2>\r\nYou’ve dutifully traced all around where you want <a href=\"https://www.dummies.com/programming/google-sketchup/how-to-paint-faces-in-sketchup-with-color-and-texture/\" target=\"_blank\" rel=\"noopener\">SketchUp to create a face</a>, but nothing’s happening. If you follow along in the image below, which was inspired by a visit to the M.C. Escher museum in Amsterdam, you see the top-left image seems to show a cube beside a rectangle, but the rectangle didn’t produce a face. In the top-right image, a diagonal line was drawn between diagonally opposite corners of the rectangle, producing two triangular faces, but something still doesn’t look right.\r\n\r\nChanging the camera position to standard front (lower-left image) and right side (lower-right image) reveals the source of the problem. It turns out that the upper-right corner of the rectangle doesn’t lie on the red-blue plane but is actually to the right of the blue-green plane, and to the right of the blue-red plane. The upper-left image isn’t really an optical illusion; it just looks like one.\r\n\r\n[caption id=\"attachment_273641\" align=\"aligncenter\" width=\"509\"]<img class=\"wp-image-273641 size-large\" src=\"https://www.dummies.com/wp-content/uploads/sketchup-problems-509x586.jpg\" alt=\"SketchUp problems \" width=\"509\" height=\"586\" /> Just because it looks right doesn’t mean that it is.[/caption]\r\n\r\nNinety percent of the time, when SketchUp doesn’t create a face where you think it should, an edge isn’t on the plane you think it’s on. To check whether your edges are coplanar, draw an edge that cuts diagonally across the area where you want a face to appear. If a face appears now, your edges aren’t all on the same plane. To fix the problem, you have to figure out which edge is the culprit, and the Color By Axis option may help you see this information at a glance. Here’s how Color By Axis works:\r\n<ol>\r\n \t<li>In the Styles panel, change your edge color from All Same to By Axis.SketchUp draws the edges in your model using the color of the axis to which they’re parallel; edges parallel to the red axis are red, and so on.</li>\r\n \t<li>Look carefully at the edges that you wanted to define your desired face.Are all the edges the color they’re supposed to be? If they’re not all supposed to be parallel to the drawing axes, this technique doesn’t do much good. But if they are, and one (or more) of them is black (instead of red or green or blue), that edge (or those edges) is your problem child. Fix it and switch back to All Same when you’re done.</li>\r\n</ol>\r\nIf the plane isn’t the problem with your edges, then check whether one edge is part of a separate group or component. To check whether you have a component problem, try hiding groups or components and checking the edges to make sure that they’re all in the group or component you think they’re in.\r\n<p class=\"article-tips tip\">A common source of this problem is <a href=\"https://www.dummies.com/programming/google-sketchup/sketchups-inferences/\" target=\"_blank\" rel=\"noopener\">SketchUp’s inferences</a>. As you slide the mouse over a face you may unwittingly be latching on to an unintended inference, such as the edge of a surface that is part of a cylinder. Watch those inference prompts, and use Undo when you complete a face but no face appears.</p>\r\n\r\n<h2 id=\"tab2\" >Your SketchUp faces are two different colors</h2>\r\nIn SketchUp, faces have two sides: a front and a back. By default, these two sides are different colors.\r\n\r\nWhen you use certain tools, such as Push/Pull or Follow Me, on a face, sometimes the faces on the resulting geometry are “inside out.” For some people, the issue is just bothersome. If you want to 3D-print your model, you need to fix the issue so that your model will print correctly.\r\n\r\nTo fix this issue, right-click the faces you want to flip and choose Reverse Faces from the context menu. If you have lots of faces to flip, you can select them all and then choose Reverse Faces to flip them all at once.\r\n\r\nIn 3D printing, this process is called checking your model’s normals.\r\n\r\nThe plan for the structure you see below was for all the outside walls to be wood siding and the interior walls to be painted yellow. But the top two images show that somehow the left wall got reversed. The bottom two images show that the problem has been solved by selecting the yellow face and reversing it.\r\n\r\n[caption id=\"attachment_273642\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-273642 size-full\" src=\"https://www.dummies.com/wp-content/uploads/sketchup-face.jpg\" alt=\"reverse SketchUp faces\" width=\"556\" height=\"476\" /> Reversing the faces in SketchUp.[/caption]\r\n<h2 id=\"tab3\" >Edges on a face won’t sink in</h2>\r\nEdges on a face tend not to sink in when you’re trying to draw a rectangle (or another geometric figure) on a face with one of SketchUp’s shape-drawing tools. Ordinarily, the Rectangle tool creates a new face on top of any face you use it on; after that, you can use Push/Pull to create a hole, if you want.\r\n\r\nWhen the edges you just drew don’t seem to cut through the face you drew them on, try these approaches:\r\n<ul>\r\n \t<li><strong>Retrace one of the edges.</strong> Sometimes that works — you’d be surprised how often.</li>\r\n \t<li><strong>Select Hidden Geometry from the View menu.</strong> You’re checking to make sure that the face you just drew isn’t crossing any hidden or smoothed edges; if it is, the face you thought was flat may not be.</li>\r\n \t<li><strong>Make sure that the face you drew on isn’t part of a group or component.</strong> If it is, undo a few steps and then redraw your shape while you edit the group or component.</li>\r\n \t<li><strong>Select the face + edges, right-click, and choose Intersect Faces→With Selection. </strong>This approach is often needed when you are working with one or more curved surfaces.</li>\r\n</ul>\r\n<h2 id=\"tab4\" >SketchUp crashed, and you lost your model</h2>\r\nUnfortunately, SketchUp crashes happen sometimes. The good news is that SketchUp automatically saves a copy of your file every five minutes.\r\n\r\nIn the web version, these autosaves are captured in Trimble Connect as revisions. You can always view the revision history for a file by navigating to it in the Trimble Connect tab (by clicking Open in the menu at the top of the screen to access Trimble Connect). For any file, you can choose to view or restore an older version.\r\n\r\nIn desktop versions, the file that SketchUp autosaves is actually a <em>separate</em> file, <em>AutoSave_yourfilename.skp</em>. If your file ever gets corrupted in a crash, an intact file is ready for you.\r\n\r\nThe problem is that most people don’t even know that the autosaved file is there. Where do you find it? If you’ve ever saved your file, the autosaved file is in the same folder as the original; therefore, it’s very important that you save your file almost immediately after starting it.\r\n<p class=\"article-tips tech\">Simple, right? Not so fast. On a Mac, you may need to change your Library folder from hidden to visible. In the Finder app, hold down the Option key while you choose Go→Library. If you don’t hold down the Option key, Library may not appear on the menu.</p>\r\nWhen you close your model, SketchUp typically assumes nothing untoward has happened and usually cleans up after itself by deleting the autosaved file.\r\n<p class=\"article-tips tip\">The really good news is that every time you save a file, SketchUp proactively saves two identical files, one with the normal file extension .SKP and the other with the file extension .SKB. You continue working on the .SKP file. If something goes really wrong with your model, you can always go back to how it was an instant before the last time you saved it. But you can’t find it in the Open File dialog box. Here’s the secret: In the Open File dialog box, go to the end of the File Name window, click the down arrow beside Sketchup Models (.SKP), and click All Files. Now the .SKB files show, and you can open them. (web: The same basic principles apply, but read more details on <a href=\"https://help.sketchup.com/en/sketchup-web/saving-opening-and-downloading-models\" target=\"_blank\" rel=\"noopener\">SketchUp's website</a>.)</p>\r\nTo minimize the amount of work you lose when software (or hardware) goes south, always do two things:\r\n<ul>\r\n \t<li>Save often — compulsively, even.</li>\r\n \t<li>Use the Save a Copy As command on the File menu.</li>\r\n</ul>\r\nWhen you’re working on a big project, the following steps can help ensure you don’t lose any work:\r\n<ol>\r\n \t<li>Save the original version of your file as <em>yourfilename_Master.skp</em>.That’s the file you’ll always be working on.</li>\r\n \t<li>Create a folder that lives in the same place as your Master file; call the folder something like <em>Your file’s name</em> Archive<strong>.</strong></li>\r\n \t<li>Every half-hour or so, choose File→Save a Copy As, and save a sequentially numbered version of your file to the Archive folder.When you’re building a big model, it’s not uncommon for your Archive folder to contain 40 or 50 saved versions of the model dating back to when the project first started.</li>\r\n \t<li>Back up regularly.At least at the end of every work session, such as when you head to a coffee or lunch break, back up your files to a low-cost, high-capacity, high-speed portable USB drive, then remove it and keep it separate from your computer. At the end of your shift, take it to a different location. You don’t need to keep it in a bank vault, just in a separate building. Take it home at night, for example.\r\n<p class=\"article-tips remember\">You can always buy new hardware and software, but you can’t buy your personal files.</p>\r\n</li>\r\n</ol>\r\n<h2 id=\"tab5\" >SketchUp is sooooo slooooooooow</h2>\r\nThe bigger your SketchUp model, the worse your computer’s performance. What makes a model big? In a nutshell, faces.\r\n\r\nDo everything in your power to keep your model as small as you can. Here are some tips for doing that:\r\n<ul>\r\n \t<li><strong>Reduce the number of sides on your extruded circles and arcs.</strong></li>\r\n \t<li><strong>Use 2D people and trees instead of 3D ones.</strong> 3D plants and people have hundreds of faces each. Consider using 2D ones instead, especially if your model won’t be seen much from overhead.</li>\r\n \t<li><strong>Use search filters in 3D Warehouse.</strong> When you’re searching for models in <a href=\"https://www.dummies.com/programming/google-sketchup/working-with-sketchups-3d-warehouse/\" target=\"_blank\" rel=\"noopener\">3D Warehouse</a>, you can restrict your search result to show only models of a certain file size or polygon (face) complexity. Especially if your model is more than 10 MB, it makes sense to keep your 3D Warehouse downloads small!</li>\r\n</ul>\r\nSome models are just big, and you can’t do much about it. Here are some tricks for working with very large SketchUp models:\r\n<ul>\r\n \t<li><strong>Make liberal use of the Outliner and tags.</strong> These SketchUp features were specifically designed to let you organize your model into manageable chunks. Hide everything you’re not working on at the moment; doing so gives your computer a fighting chance.</li>\r\n \t<li><strong>Substitute simple forms for large numbers of complex components.</strong> For example, insert sticks as placeholders for big sets of 3D trees, cars, and other big components.</li>\r\n \t<li><strong>Turn off shadows and switch to a simple style, such as Shaded in the Default Styles collection.</strong> It takes a lot of computer horsepower to display shadows, edge effects, and textures in real time on your monitor. When you’re working, turn off all that stuff.</li>\r\n \t<li><strong>Use scenes to navigate between views.</strong> Scenes aren’t just for presenting your model; they’re also great for working with it. If you create scenes for the different views you commonly use and with different combinations of hidden geometry, then you don’t have to orbit, pan, and zoom around your gigantic model. To speed up things even more, deselect Enable Scene Transitions in the Animation panel of the Model Info dialog box. (web: Animation settings are in the Scenes panel.)</li>\r\n</ul>\r\n<h2 id=\"tab6\" >You can’t get a good view of the inside of your SketchUp model</h2>\r\nIt’s not always easy to work on the inside of something in SketchUp. You can do these things to make it easier, though:\r\n<ul>\r\n \t<li><strong>Cut into your model with section</strong> SketchUp’s Sections feature lets you cut away parts of your model — temporarily, of course — so that you can get a better view of what’s inside.</li>\r\n \t<li><strong>Widen your field of view. </strong><em>Field of view</em> is the part of your model you can see onscreen at one time. A wider FOV is like having better peripheral vision.</li>\r\n</ul>\r\n<p class=\"article-tips tip\">You can change the field of view only when in Perspective view mode, but the setting will be remembered if you then switch to Parallel view mode.</p>\r\nThe image below shows the plan view of a room. If you zoom or walk in through the door — oops, tunnel vision. Increase peripheral vision by changing your <a href=\"https://www.dummies.com/programming/google-sketchup/how-to-set-your-field-of-view-in-google-sketchup-8/\" target=\"_blank\" rel=\"noopener\">field of view</a>. Ah, that’s better! Now you can see that the picture hanging on the wall is the floor plan of this room.\r\n\r\n[caption id=\"attachment_273643\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-273643 size-full\" src=\"https://www.dummies.com/wp-content/uploads/sketchup-field-of-view.jpg\" alt=\"SketchUp field of view\" width=\"556\" height=\"316\" /> Changing SketchUp's field of view makes a world of difference.[/caption]\r\n<h2 id=\"tab7\" >A face flashes when you orbit in SketchUp</h2>\r\nIf you have two faces in the same spot — maybe one is in a separate group or component — you see a <em>Z-fighting</em> effect. SketchUp is deciding which face to display by switching back and forth between them; it’s not a good solution, but certainly a logical one — at least for a piece of software. The image below attempts to portray this effect in a single image. The only way to get rid of Z-fighting is to delete or hide one of the faces.\r\n\r\n[caption id=\"attachment_273644\" align=\"aligncenter\" width=\"556\"]<img class=\"wp-image-273644 size-full\" src=\"https://www.dummies.com/wp-content/uploads/sketchup-faces.jpg\" alt=\"SketchUp face flashing\" width=\"556\" height=\"308\" /> Two faces fighting for the same 3D real estate.[/caption]\r\n<h2 id=\"tab8\" >You can’t move your SketchUp component the way you want</h2>\r\nWhen you insert some components into your model, the components by default glue to faces. A glued component instance isn’t actually glued in one place. Instead, it’s glued to the plane of the face you originally placed (or created) it on. For example, if you place a sofa component on the floor of your living room, you can move it around only on that plane — not up and down.\r\n\r\nThis gluing behavior comes in handy when you deal with things like furniture; it allows you to rearrange things with the Move tool without accidentally picking them up.\r\n\r\nIf you can’t move your component the way you want to, right-click it to see whether Unglue is an option; if it is, choose it. Now you can move your component around however you want.\r\n<h2 id=\"tab9\" >Bad stuff happens almost every time you use SketchUp’s Eraser</h2>\r\nWhen you use the Eraser tool, it’s pretty easy to delete stuff accidentally. Worse, you usually don’t notice what’s missing until it’s too late. Here are some tips for erasing more accurately:\r\n<ul>\r\n \t<li><strong>Orbit around.</strong> Try to make sure that nothing is behind whatever you’re erasing; use SketchUp’s navigation tools to get a view of your model that puts you out of danger.</li>\r\n \t<li><strong>Switch on Back Edges.</strong> When you’re doing a lot of erasing, choose View→Edge Style→Back Edges. That way, you can see every edge in your model, and you’re less likely to erase the wrong ones.</li>\r\n \t<li><strong>Use the Undo modifier of the eraser. </strong>Follow along starting in the upper-left image you see below. The intent is to erase the four edges in the center to create a single face. While erasing, you can select multiple objects by holding down the left mouse button while dragging the eraser over them. Oh, great googly moogly (or words to that effect) — you selected some things you didn’t want to erase. No problem: <em>Don’t</em> release the mouse button, but press and hold down the keyboard Alt key (Mac: <strong>⌘</strong>). Now anything you drag the eraser over will be unselected. You can switch back and forth as desired, but nothing actually gets erased until you release the mouse button.</li>\r\n \t<li><strong>Double-check.</strong> After you do a lot of erasing, give your model a quick once-over with the Orbit tool, just to make sure that you didn’t get rid of anything important. Put a sticky note on your computer monitor that says something like <em>Check after Erase!</em> just to remind you.</li>\r\n</ul>\r\n[caption id=\"attachment_273645\" align=\"aligncenter\" width=\"442\"]<img class=\"wp-image-273645 size-large\" src=\"https://www.dummies.com/wp-content/uploads/sketchup-uneraser-442x586.jpg\" alt=\"SketchUp uneraser\" width=\"442\" height=\"586\" /> The uneraser in action.[/caption]\r\n<h2 id=\"tab10\" >All your edges and faces have different tags</h2>\r\nUsing Tags in SketchUp can be a dangerous business. Here’s the short version of some good advice: Always build everything on Untagged, and assign whole groups or components to other tags only if you really need to.\r\n\r\nIf you used tags in SketchUp and now things are messed up, here’s what you can do to recover:\r\n<ol>\r\n \t<li>Make sure that everything is visible.Select Hidden Geometry on the View menu; then (in the Tags panel) make all your tags visible. Just make sure that you can see everything in your model.</li>\r\n \t<li>Choose Edit→Select All.</li>\r\n \t<li>In the Entity Info panel, move everything to Layer0.</li>\r\n \t<li>In the Tags panel, delete your other tags.</li>\r\n \t<li>When you’re prompted, tell SketchUp to move anything remaining on them to Untagged.</li>\r\n \t<li>Create new tags and follow best practices to avoid problems.</li>\r\n</ol>\r\n<p class=\"article-tips tip\">If you’ve downloaded 3D Warehouse models, you’ll probably find that they have some tags that you don’t understand and might want to get rid of. They may have had significance to the original creator, but they can become clutter in your file, so they should be removed.</p>\r\nWant to learn more? Check out our <a href=\"https://www.dummies.com/programming/google-sketchup/sketchup-for-dummies-cheat-sheet/\" target=\"_blank\" rel=\"noopener\">SketchUp Cheat Sheet</a>.","blurb":"","authors":[{"authorId":9621,"name":"Bill Fane","slug":"bill-fane","description":" <p><b>Bill Fane</b> was a doorknob designer for many years. Then, in 1996, he began teaching mechanical design, including courses in AutoCAD, Inventor, SolidWorks, and machine design. Having used AutoCAD since Version 2.17g debuted in 1986, Bill lectured on a wide range of AutoCAD and Inventor subjects at Autodesk University from 1995 to 2012. He has written extensively for <i>CADalyst</i> magazine. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/9621"}},{"authorId":33377,"name":"Mark Harrison","slug":"mark-harrison","description":" <p><b>Bill Fane</b> is the author of <i>AutoCAD For Dummies</i>. He spent years as a product designer before becoming an educator focused on design tools. <b>Mark Harrison</b> is a product manager for Trimble, Inc., SketchUp&#39;s parent company. He studies learnability in 3D software. <b>Josh Reilly</b> is a training manager with Trimble and a longtime SketchUp instructor. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33377"}},{"authorId":33376,"name":"Josh Reilly","slug":"josh-reilly","description":" <p><b>Bill Fane</b> is the author of <i>AutoCAD For Dummies</i>. He spent years as a product designer before becoming an educator focused on design tools. <b>Mark Harrison</b> is a product manager for Trimble, Inc., SketchUp&#39;s parent company. He studies learnability in 3D software. <b>Josh Reilly</b> is a training manager with Trimble and a longtime SketchUp instructor. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33376"}}],"primaryCategoryTaxonomy":{"categoryId":33636,"title":"SketchUp","slug":"sketchup","_links":{"self":"https://dummies-api.dummies.com/v2/categories/33636"}},"secondaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"tertiaryCategoryTaxonomy":{"categoryId":0,"title":null,"slug":null,"_links":null},"trendingArticles":null,"inThisArticle":[{"label":"SketchUp won’t create a face where you want it to","target":"#tab1"},{"label":"Your SketchUp faces are two different colors","target":"#tab2"},{"label":"Edges on a face won’t sink in","target":"#tab3"},{"label":"SketchUp crashed, and you lost your model","target":"#tab4"},{"label":"SketchUp is sooooo slooooooooow","target":"#tab5"},{"label":"You can’t get a good view of the inside of your SketchUp model","target":"#tab6"},{"label":"A face flashes when you orbit in SketchUp","target":"#tab7"},{"label":"You can’t move your SketchUp component the way you want","target":"#tab8"},{"label":"Bad stuff happens almost every time you use SketchUp’s Eraser","target":"#tab9"},{"label":"All your edges and faces have different tags","target":"#tab10"}],"relatedArticles":{"fromBook":[{"articleId":273651,"title":"10 SketchUp Quick Wins","slug":"10-sketchup-quick-wins","categoryList":["technology","software","design-software","sketchup"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/273651"}},{"articleId":273632,"title":"Working with SketchUp’s 3D Warehouse","slug":"working-with-sketchups-3d-warehouse","categoryList":["technology","software","design-software","sketchup"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/273632"}},{"articleId":207678,"title":"SketchUp For Dummies Cheat Sheet","slug":"sketchup-for-dummies-cheat-sheet","categoryList":["technology","software","design-software","sketchup"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/207678"}},{"articleId":188813,"title":"How to Print to Scale in SketchUp for Web","slug":"how-to-print-to-scale-in-sketchup-for-web","categoryList":["technology","software","design-software","sketchup"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/188813"}},{"articleId":152331,"title":"13 Keyboard Shortcuts for Common SketchUp Tools","slug":"13-keyboard-shortcuts-for-common-sketchup-tools","categoryList":["technology","software","design-software","sketchup"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/152331"}}],"fromCategory":[{"articleId":273651,"title":"10 SketchUp Quick Wins","slug":"10-sketchup-quick-wins","categoryList":["technology","software","design-software","sketchup"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/273651"}},{"articleId":273632,"title":"Working with SketchUp’s 3D Warehouse","slug":"working-with-sketchups-3d-warehouse","categoryList":["technology","software","design-software","sketchup"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/273632"}},{"articleId":241390,"title":"How to Animate Sections with Scenes in SketchUp","slug":"animate-sections-scenes-sketchup","categoryList":["technology","software","design-software","sketchup"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/241390"}},{"articleId":241380,"title":"How to Make Walkthroughs in SketchUp","slug":"make-walkthroughs-sketchup","categoryList":["technology","software","design-software","sketchup"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/241380"}},{"articleId":241348,"title":"How to Use SketchUp’s CleanUp3 and Solid Inspector2 Tools for 3D Printing","slug":"use-sketchups-cleanup3-solid-inspector2-tools-3d-printing","categoryList":["technology","software","design-software","sketchup"],"_links":{"self":"https://dummies-api.dummies.com/v2/articles/241348"}}]},"hasRelatedBookFromSearch":false,"relatedBook":{"bookId":281864,"slug":"sketchup-for-dummies-2nd-edition","isbn":"9781119617938","categoryList":["technology","software","design-software","sketchup"],"amazon":{"default":"https://www.amazon.com/gp/product/1119617936/ref=as_li_tl?ie=UTF8&tag=wiley01-20","ca":"https://www.amazon.ca/gp/product/1119617936/ref=as_li_tl?ie=UTF8&tag=wiley01-20","indigo_ca":"http://www.tkqlhce.com/click-9208661-13710633?url=https://www.chapters.indigo.ca/en-ca/books/product/1119617936-item.html&cjsku=978111945484","gb":"https://www.amazon.co.uk/gp/product/1119617936/ref=as_li_tl?ie=UTF8&tag=wiley01-20","de":"https://www.amazon.de/gp/product/1119617936/ref=as_li_tl?ie=UTF8&tag=wiley01-20"},"image":{"src":"https://www.dummies.com/wp-content/uploads/sketchup-for-dummies-2nd-edition-cover-9781119617938-203x255.jpg","width":203,"height":255},"title":"SketchUp For Dummies, 2nd Edition","testBankPinActivationLink":"","bookOutOfPrint":true,"authorsInfo":"<p><p><b><b data-author-id=\"9621\">Bill Fane</b></b> was a doorknob designer for many years. Then, in 1996, he began teaching mechanical design, including courses in AutoCAD, Inventor, SolidWorks, and machine design. Having used AutoCAD since Version 2.17g debuted in 1986, Bill lectured on a wide range of AutoCAD and Inventor subjects at Autodesk University from 1995 to 2012. He has written extensively for <i>CADalyst</i> magazine. <p><b>Bill Fane</b> is the author of <i>AutoCAD For Dummies</i>. He spent years as a product designer before becoming an educator focused on design tools. <b><b data-author-id=\"33377\">Mark Harrison</b></b> is a product manager for Trimble, Inc., SketchUp&#39;s parent company. He studies learnability in 3D software. <b>Josh Reilly</b> is a training manager with Trimble and a longtime SketchUp instructor. <p><b>Bill Fane</b> is the author of <i>AutoCAD For Dummies</i>. He spent years as a product designer before becoming an educator focused on design tools. <b>Mark Harrison</b> is a product manager for Trimble, Inc., SketchUp&#39;s parent company. He studies learnability in 3D software. <b><b data-author-id=\"33376\">Josh Reilly</b></b> is a training manager with Trimble and a longtime SketchUp instructor.</p>","authors":[{"authorId":9621,"name":"Bill Fane","slug":"bill-fane","description":" <p><b>Bill Fane</b> was a doorknob designer for many years. Then, in 1996, he began teaching mechanical design, including courses in AutoCAD, Inventor, SolidWorks, and machine design. Having used AutoCAD since Version 2.17g debuted in 1986, Bill lectured on a wide range of AutoCAD and Inventor subjects at Autodesk University from 1995 to 2012. He has written extensively for <i>CADalyst</i> magazine. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/9621"}},{"authorId":33377,"name":"Mark Harrison","slug":"mark-harrison","description":" <p><b>Bill Fane</b> is the author of <i>AutoCAD For Dummies</i>. He spent years as a product designer before becoming an educator focused on design tools. <b>Mark Harrison</b> is a product manager for Trimble, Inc., SketchUp&#39;s parent company. He studies learnability in 3D software. <b>Josh Reilly</b> is a training manager with Trimble and a longtime SketchUp instructor. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33377"}},{"authorId":33376,"name":"Josh Reilly","slug":"josh-reilly","description":" <p><b>Bill Fane</b> is the author of <i>AutoCAD For Dummies</i>. He spent years as a product designer before becoming an educator focused on design tools. <b>Mark Harrison</b> is a product manager for Trimble, Inc., SketchUp&#39;s parent company. He studies learnability in 3D software. <b>Josh Reilly</b> is a training manager with Trimble and a longtime SketchUp instructor. ","_links":{"self":"https://dummies-api.dummies.com/v2/authors/33376"}}],"_links":{"self":"https://dummies-api.dummies.com/v2/books/"}},"collections":[],"articleAds":{"footerAd":"<div class=\"du-ad-region row\" id=\"article_page_adhesion_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_adhesion_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;software&quot;,&quot;design-software&quot;,&quot;sketchup&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119617938&quot;]}]\" id=\"du-slot-62f3f261ac56b\"></div></div>","rightAd":"<div class=\"du-ad-region row\" id=\"article_page_right_ad\"><div class=\"du-ad-unit col-md-12\" data-slot-id=\"article_page_right_ad\" data-refreshed=\"false\" \r\n data-target = \"[{&quot;key&quot;:&quot;cat&quot;,&quot;values&quot;:[&quot;technology&quot;,&quot;software&quot;,&quot;design-software&quot;,&quot;sketchup&quot;]},{&quot;key&quot;:&quot;isbn&quot;,&quot;values&quot;:[&quot;9781119617938&quot;]}]\" id=\"du-slot-62f3f261acdf8\"></div></div>"},"articleType":{"articleType":"Articles","articleList":null,"content":null,"videoInfo":{"videoId":null,"name":null,"accountId":null,"playerId":null,"thumbnailUrl":null,"description":null,"uploadDate":null}},"sponsorship":{"sponsorshipPage":false,"backgroundImage":{"src":null,"width":0,"height":0},"brandingLine":"","brandingLink":"","brandingLogo":{"src":null,"width":0,"height":0},"sponsorAd":"","sponsorEbookTitle":"","sponsorEbookLink":"","sponsorEbookImage":{"src":null,"width":0,"height":0}},"primaryLearningPath":"Advance","lifeExpectancy":"One year","lifeExpectancySetFrom":"2022-08-10T00:00:00+00:00","dummiesForKids":"no","sponsoredContent":"no","adInfo":"","adPairKey":[]},"status":"publish","visibility":"public","articleId":273640}],"_links":{"self":{"self":"https://dummies-api.dummies.com/v2/categories/33512/categoryArticles?sortField=time&sortOrder=1&size=10&offset=0"},"next":{"self":"https://dummies-api.dummies.com/v2/categories/33512/categoryArticles?sortField=time&sortOrder=1&size=10&offset=10"},"last":{"self":"https://dummies-api.dummies.com/v2/categories/33512/categoryArticles?sortField=time&sortOrder=1&size=10&offset=9359"}}},"objectTitle":"","status":"success","pageType":"article-category","objectId":"33512","page":1,"sortField":"time","sortOrder":1,"categoriesIds":[],"articleTypes":[],"filterData":{"categoriesFilter":[{"itemId":0,"itemName":"All Categories","count":9362},{"itemId":33513,"itemName":"Computers","count":1403},{"itemId":33537,"itemName":"Cybersecurity","count":51},{"itemId":33538,"itemName":"Digital Audio & Radio","count":127},{"itemId":33543,"itemName":"Electronics","count":1748},{"itemId":33572,"itemName":"Information Technology","count":794},{"itemId":33587,"itemName":"Internet Basics","count":86},{"itemId":33588,"itemName":"Notable Websites","count":187},{"itemId":33592,"itemName":"Programming & Web Design","count":1390},{"itemId":33611,"itemName":"Social Media","count":378},{"itemId":33618,"itemName":"Software","count":3197},{"itemId":33512,"itemName":"Technology","count":1}],"articleTypeFilter":[{"articleType":"All Types","count":9362},{"articleType":"Articles","count":8235},{"articleType":"Cheat Sheet","count":278},{"articleType":"Step by Step","count":763},{"articleType":"Videos","count":86}]},"filterDataLoadedStatus":"success","pageSize":10},"adsState":{"pageScripts":{"headers":{"timestamp":"2022-08-15T06:59:02+00:00"},"adsId":0,"data":{"scripts":[{"pages":["all"],"location":"header","script":"<!--Optimizely Script-->\r\n<script src=\"https://cdn.optimizely.com/js/10563184655.js\"></script>","enabled":false},{"pages":["all"],"location":"header","script":"<!-- comScore Tag -->\r\n<script>var _comscore = _comscore || [];_comscore.push({ c1: \"2\", c2: \"15097263\" });(function() {var s = document.createElement(\"script\"), el = document.getElementsByTagName(\"script\")[0]; s.async = true;s.src = (document.location.protocol == \"https:\" ? \"https://sb\" : \"http://b\") + \".scorecardresearch.com/beacon.js\";el.parentNode.insertBefore(s, el);})();</script><noscript><img src=\"https://sb.scorecardresearch.com/p?c1=2&c2=15097263&cv=2.0&cj=1\" /></noscript>\r\n<!-- / comScore Tag -->","enabled":true},{"pages":["all"],"location":"footer","script":"<!--BEGIN QUALTRICS WEBSITE FEEDBACK SNIPPET-->\r\n<script type='text/javascript'>\r\n(function(){var g=function(e,h,f,g){\r\nthis.get=function(a){for(var a=a+\"=\",c=document.cookie.split(\";\"),b=0,e=c.length;b<e;b++){for(var d=c[b];\" \"==d.charAt(0);)d=d.substring(1,d.length);if(0==d.indexOf(a))return d.substring(a.length,d.length)}return null};\r\nthis.set=function(a,c){var b=\"\",b=new Date;b.setTime(b.getTime()+6048E5);b=\"; expires=\"+b.toGMTString();document.cookie=a+\"=\"+c+b+\"; path=/; \"};\r\nthis.check=function(){var a=this.get(f);if(a)a=a.split(\":\");else if(100!=e)\"v\"==h&&(e=Math.random()>=e/100?0:100),a=[h,e,0],this.set(f,a.join(\":\"));else return!0;var c=a[1];if(100==c)return!0;switch(a[0]){case \"v\":return!1;case \"r\":return c=a[2]%Math.floor(100/c),a[2]++,this.set(f,a.join(\":\")),!c}return!0};\r\nthis.go=function(){if(this.check()){var a=document.createElement(\"script\");a.type=\"text/javascript\";a.src=g;document.body&&document.body.appendChild(a)}};\r\nthis.start=function(){var t=this;\"complete\"!==document.readyState?window.addEventListener?window.addEventListener(\"load\",function(){t.go()},!1):window.attachEvent&&window.attachEvent(\"onload\",function(){t.go()}):t.go()};};\r\ntry{(new g(100,\"r\",\"QSI_S_ZN_5o5yqpvMVjgDOuN\",\"https://zn5o5yqpvmvjgdoun-wiley.siteintercept.qualtrics.com/SIE/?Q_ZID=ZN_5o5yqpvMVjgDOuN\")).start()}catch(i){}})();\r\n</script><div id='ZN_5o5yqpvMVjgDOuN'><!--DO NOT REMOVE-CONTENTS PLACED HERE--></div>\r\n<!--END WEBSITE FEEDBACK SNIPPET-->","enabled":false},{"pages":["all"],"location":"header","script":"<!-- Hotjar Tracking Code for http://www.dummies.com -->\r\n<script>\r\n (function(h,o,t,j,a,r){\r\n h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};\r\n h._hjSettings={hjid:257151,hjsv:6};\r\n a=o.getElementsByTagName('head')[0];\r\n r=o.createElement('script');r.async=1;\r\n r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;\r\n a.appendChild(r);\r\n })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');\r\n</script>","enabled":false},{"pages":["article"],"location":"header","script":"<!-- //Connect Container: dummies --> <script src=\"//get.s-onetag.com/bffe21a1-6bb8-4928-9449-7beadb468dae/tag.min.js\" async defer></script>","enabled":true},{"pages":["homepage"],"location":"header","script":"<meta name=\"facebook-domain-verification\" content=\"irk8y0irxf718trg3uwwuexg6xpva0\" />","enabled":true},{"pages":["homepage","article","category","search"],"location":"footer","script":"<!-- Facebook Pixel Code -->\r\n<noscript>\r\n<img height=\"1\" width=\"1\" src=\"https://www.facebook.com/tr?id=256338321977984&ev=PageView&noscript=1\"/>\r\n</noscript>\r\n<!-- End Facebook Pixel Code -->","enabled":true}]}},"pageScriptsLoadedStatus":"success"},"navigationState":{"navigationCollections":[{"collectionId":287568,"title":"BYOB (Be Your Own Boss)","hasSubCategories":false,"url":"/collection/for-the-entry-level-entrepreneur-287568"},{"collectionId":293237,"title":"Be a Rad Dad","hasSubCategories":false,"url":"/collection/be-the-best-dad-293237"},{"collectionId":294090,"title":"Contemplating the Cosmos","hasSubCategories":false,"url":"/collection/theres-something-about-space-294090"},{"collectionId":287563,"title":"For Those Seeking Peace of Mind","hasSubCategories":false,"url":"/collection/for-those-seeking-peace-of-mind-287563"},{"collectionId":287570,"title":"For the Aspiring Aficionado","hasSubCategories":false,"url":"/collection/for-the-bougielicious-287570"},{"collectionId":291903,"title":"For the Budding Cannabis Enthusiast","hasSubCategories":false,"url":"/collection/for-the-budding-cannabis-enthusiast-291903"},{"collectionId":291934,"title":"For the Exam-Season Crammer","hasSubCategories":false,"url":"/collection/for-the-exam-season-crammer-291934"},{"collectionId":287569,"title":"For the Hopeless Romantic","hasSubCategories":false,"url":"/collection/for-the-hopeless-romantic-287569"},{"collectionId":287567,"title":"For the Unabashed Hippie","hasSubCategories":false,"url":"/collection/for-the-unabashed-hippie-287567"},{"collectionId":292186,"title":"Just DIY It","hasSubCategories":false,"url":"/collection/just-diy-it-292186"}],"navigationCollectionsLoadedStatus":"success","navigationCategories":{"books":{"0":{"data":[{"categoryId":33512,"title":"Technology","hasSubCategories":true,"url":"/category/books/technology-33512"},{"categoryId":33662,"title":"Academics & The Arts","hasSubCategories":true,"url":"/category/books/academics-the-arts-33662"},{"categoryId":33809,"title":"Home, Auto, & Hobbies","hasSubCategories":true,"url":"/category/books/home-auto-hobbies-33809"},{"categoryId":34038,"title":"Body, Mind, & Spirit","hasSubCategories":true,"url":"/category/books/body-mind-spirit-34038"},{"categoryId":34224,"title":"Business, Careers, & Money","hasSubCategories":true,"url":"/category/books/business-careers-money-34224"}],"breadcrumbs":[],"categoryTitle":"Level 0 Category","mainCategoryUrl":"/category/books/level-0-category-0"}},"articles":{"0":{"data":[{"categoryId":33512,"title":"Technology","hasSubCategories":true,"url":"/category/articles/technology-33512"},{"categoryId":33662,"title":"Academics & The Arts","hasSubCategories":true,"url":"/category/articles/academics-the-arts-33662"},{"categoryId":33809,"title":"Home, Auto, & Hobbies","hasSubCategories":true,"url":"/category/articles/home-auto-hobbies-33809"},{"categoryId":34038,"title":"Body, Mind, & Spirit","hasSubCategories":true,"url":"/category/articles/body-mind-spirit-34038"},{"categoryId":34224,"title":"Business, Careers, & Money","hasSubCategories":true,"url":"/category/articles/business-careers-money-34224"}],"breadcrumbs":[],"categoryTitle":"Level 0 Category","mainCategoryUrl":"/category/articles/level-0-category-0"}}},"navigationCategoriesLoadedStatus":"success"},"searchState":{"searchList":[],"searchStatus":"initial","relatedArticlesList":[],"relatedArticlesStatus":"initial"},"routeState":{"name":"ArticleCategory","path":"/category/articles/technology-33512/","hash":"","query":{},"params":{"category":"technology-33512"},"fullPath":"/category/articles/technology-33512/","meta":{"routeType":"category","breadcrumbInfo":{"suffix":"Articles","baseRoute":"/category/articles"},"prerenderWithAsyncData":true},"from":{"name":null,"path":"/","hash":"","query":{},"params":{},"fullPath":"/","meta":{}}},"sfmcState":{"status":"initial"},"profileState":{"auth":{},"userOptions":{},"status":"initial"}}
Logo
  • Articles Open Article Categories
  • Books Open Book Categories
  • Collections Open Collections list
  • Custom Solutions

Article Categories

Book Categories

Collections

Explore all collections
BYOB (Be Your Own Boss)
Be a Rad Dad
Contemplating the Cosmos
For Those Seeking Peace of Mind
For the Aspiring Aficionado
For the Budding Cannabis Enthusiast
For the Exam-Season Crammer
For the Hopeless Romantic
For the Unabashed Hippie
Just DIY It
Log In
  • Home
  • Technology Articles

Technology Articles

Technology. It makes the world go 'round. And whether you're a self-confessed techie or a total newbie, you'll find something to love among our hundreds of technology articles and books.

Browse By Category

Computers

Computers

Cybersecurity

Cybersecurity

Digital Audio & Radio

Digital Audio & Radio

Electronics

Electronics

Information Technology

Information Technology

Internet Basics

Internet Basics

Notable Websites

Notable Websites

Programming & Web Design

Programming & Web Design

Social Media

Social Media

Software

Software

Previous slideNext slide
Computers

Computers

Cybersecurity

Cybersecurity

Digital Audio & Radio

Digital Audio & Radio

Electronics

Electronics

Information Technology

Information Technology

Internet Basics

Internet Basics

Notable Websites

Notable Websites

Programming & Web Design

Programming & Web Design

Social Media

Social Media

Software

Software

Articles From Technology

page 1
page 2
page 3
page 4
page 5
page 6
page 7
page 8
page 9
page 10
page 11
page 12
page 13
page 14
page 15
page 16
page 17
page 18
page 19
page 20
page 21
page 22
page 23
page 24
page 25
page 26
page 27
page 28
page 29
page 30
page 31
page 32
page 33
page 34
page 35
page 36
page 37
page 38
page 39
page 40
page 41
page 42
page 43
page 44
page 45
page 46
page 47
page 48
page 49
page 50
page 51
page 52
page 53
page 54
page 55
page 56
page 57
page 58
page 59
page 60
page 61
page 62
page 63
page 64
page 65
page 66
page 67
page 68
page 69
page 70
page 71
page 72
page 73
page 74
page 75
page 76
page 77
page 78
page 79
page 80
page 81
page 82
page 83
page 84
page 85
page 86
page 87
page 88
page 89
page 90
page 91
page 92
page 93
page 94
page 95
page 96
page 97
page 98
page 99
page 100
page 101
page 102
page 103
page 104
page 105
page 106
page 107
page 108
page 109
page 110
page 111
page 112
page 113
page 114
page 115
page 116
page 117
page 118
page 119
page 120
page 121
page 122
page 123
page 124
page 125
page 126
page 127
page 128
page 129
page 130
page 131
page 132
page 133
page 134
page 135
page 136
page 137
page 138
page 139
page 140
page 141
page 142
page 143
page 144
page 145
page 146
page 147
page 148
page 149
page 150
page 151
page 152
page 153
page 154
page 155
page 156
page 157
page 158
page 159
page 160
page 161
page 162
page 163
page 164
page 165
page 166
page 167
page 168
page 169
page 170
page 171
page 172
page 173
page 174
page 175
page 176
page 177
page 178
page 179
page 180
page 181
page 182
page 183
page 184
page 185
page 186
page 187
page 188
page 189
page 190
page 191
page 192
page 193
page 194
page 195
page 196
page 197
page 198
page 199
page 200
page 201
page 202
page 203
page 204
page 205
page 206
page 207
page 208
page 209
page 210
page 211
page 212
page 213
page 214
page 215
page 216
page 217
page 218
page 219
page 220
page 221
page 222
page 223
page 224
page 225
page 226
page 227
page 228
page 229
page 230
page 231
page 232
page 233
page 234
page 235
page 236
page 237
page 238
page 239
page 240
page 241
page 242
page 243
page 244
page 245
page 246
page 247
page 248
page 249
page 250
page 251
page 252
page 253
page 254
page 255
page 256
page 257
page 258
page 259
page 260
page 261
page 262
page 263
page 264
page 265
page 266
page 267
page 268
page 269
page 270
page 271
page 272
page 273
page 274
page 275
page 276
page 277
page 278
page 279
page 280
page 281
page 282
page 283
page 284
page 285
page 286
page 287
page 288
page 289
page 290
page 291
page 292
page 293
page 294
page 295
page 296
page 297
page 298
page 299
page 300
page 301
page 302
page 303
page 304
page 305
page 306
page 307
page 308
page 309
page 310
page 311
page 312
page 313
page 314
page 315
page 316
page 317
page 318
page 319
page 320
page 321
page 322
page 323
page 324
page 325
page 326
page 327
page 328
page 329
page 330
page 331
page 332
page 333
page 334
page 335
page 336
page 337
page 338
page 339
page 340
page 341
page 342
page 343
page 344
page 345
page 346
page 347
page 348
page 349
page 350
page 351
page 352
page 353
page 354
page 355
page 356
page 357
page 358
page 359
page 360
page 361
page 362
page 363
page 364
page 365
page 366
page 367
page 368
page 369
page 370
page 371
page 372
page 373
page 374
page 375
page 376
page 377
page 378
page 379
page 380
page 381
page 382
page 383
page 384
page 385
page 386
page 387
page 388
page 389
page 390
page 391
page 392
page 393
page 394
page 395
page 396
page 397
page 398
page 399
page 400
page 401
page 402
page 403
page 404
page 405
page 406
page 407
page 408
page 409
page 410
page 411
page 412
page 413
page 414
page 415
page 416
page 417
page 418
page 419
page 420
page 421
page 422
page 423
page 424
page 425
page 426
page 427
page 428
page 429
page 430
page 431
page 432
page 433
page 434
page 435
page 436
page 437
page 438
page 439
page 440
page 441
page 442
page 443
page 444
page 445
page 446
page 447
page 448
page 449
page 450
page 451
page 452
page 453
page 454
page 455
page 456
page 457
page 458
page 459
page 460
page 461
page 462
page 463
page 464
page 465
page 466
page 467
page 468
page 469
page 470
page 471
page 472
page 473
page 474
page 475
page 476
page 477
page 478
page 479
page 480
page 481
page 482
page 483
page 484
page 485
page 486
page 487
page 488
page 489
page 490
page 491
page 492
page 493
page 494
page 495
page 496
page 497
page 498
page 499
page 500
page 501
page 502
page 503
page 504
page 505
page 506
page 507
page 508
page 509
page 510
page 511
page 512
page 513
page 514
page 515
page 516
page 517
page 518
page 519
page 520
page 521
page 522
page 523
page 524
page 525
page 526
page 527
page 528
page 529
page 530
page 531
page 532
page 533
page 534
page 535
page 536
page 537
page 538
page 539
page 540
page 541
page 542
page 543
page 544
page 545
page 546
page 547
page 548
page 549
page 550
page 551
page 552
page 553
page 554
page 555
page 556
page 557
page 558
page 559
page 560
page 561
page 562
page 563
page 564
page 565
page 566
page 567
page 568
page 569
page 570
page 571
page 572
page 573
page 574
page 575
page 576
page 577
page 578
page 579
page 580
page 581
page 582
page 583
page 584
page 585
page 586
page 587
page 588
page 589
page 590
page 591
page 592
page 593
page 594
page 595
page 596
page 597
page 598
page 599
page 600
page 601
page 602
page 603
page 604
page 605
page 606
page 607
page 608
page 609
page 610
page 611
page 612
page 613
page 614
page 615
page 616
page 617
page 618
page 619
page 620
page 621
page 622
page 623
page 624
page 625
page 626
page 627
page 628
page 629
page 630
page 631
page 632
page 633
page 634
page 635
page 636
page 637
page 638
page 639
page 640
page 641
page 642
page 643
page 644
page 645
page 646
page 647
page 648
page 649
page 650
page 651
page 652
page 653
page 654
page 655
page 656
page 657
page 658
page 659
page 660
page 661
page 662
page 663
page 664
page 665
page 666
page 667
page 668
page 669
page 670
page 671
page 672
page 673
page 674
page 675
page 676
page 677
page 678
page 679
page 680
page 681
page 682
page 683
page 684
page 685
page 686
page 687
page 688
page 689
page 690
page 691
page 692
page 693
page 694
page 695
page 696
page 697
page 698
page 699
page 700
page 701
page 702
page 703
page 704
page 705
page 706
page 707
page 708
page 709
page 710
page 711
page 712
page 713
page 714
page 715
page 716
page 717
page 718
page 719
page 720
page 721
page 722
page 723
page 724
page 725
page 726
page 727
page 728
page 729
page 730
page 731
page 732
page 733
page 734
page 735
page 736
page 737
page 738
page 739
page 740
page 741
page 742
page 743
page 744
page 745
page 746
page 747
page 748
page 749
page 750
page 751
page 752
page 753
page 754
page 755
page 756
page 757
page 758
page 759
page 760
page 761
page 762
page 763
page 764
page 765
page 766
page 767
page 768
page 769
page 770
page 771
page 772
page 773
page 774
page 775
page 776
page 777
page 778
page 779
page 780
page 781
page 782
page 783
page 784
page 785
page 786
page 787
page 788
page 789
page 790
page 791
page 792
page 793
page 794
page 795
page 796
page 797
page 798
page 799
page 800
page 801
page 802
page 803
page 804
page 805
page 806
page 807
page 808
page 809
page 810
page 811
page 812
page 813
page 814
page 815
page 816
page 817
page 818
page 819
page 820
page 821
page 822
page 823
page 824
page 825
page 826
page 827
page 828
page 829
page 830
page 831
page 832
page 833
page 834
page 835
page 836
page 837
page 838
page 839
page 840
page 841
page 842
page 843
page 844
page 845
page 846
page 847
page 848
page 849
page 850
page 851
page 852
page 853
page 854
page 855
page 856
page 857
page 858
page 859
page 860
page 861
page 862
page 863
page 864
page 865
page 866
page 867
page 868
page 869
page 870
page 871
page 872
page 873
page 874
page 875
page 876
page 877
page 878
page 879
page 880
page 881
page 882
page 883
page 884
page 885
page 886
page 887
page 888
page 889
page 890
page 891
page 892
page 893
page 894
page 895
page 896
page 897
page 898
page 899
page 900
page 901
page 902
page 903
page 904
page 905
page 906
page 907
page 908
page 909
page 910
page 911
page 912
page 913
page 914
page 915
page 916
page 917
page 918
page 919
page 920
page 921
page 922
page 923
page 924
page 925
page 926
page 927
page 928
page 929
page 930
page 931
page 932
page 933
page 934
page 935
page 936
page 937

Filter Results

9,369 results
9,369 results
General Microsoft Windows 365 For Dummies Cheat Sheet

Cheat Sheet / Updated 08-12-2022

Windows 365 is Microsoft’s cloud-based operating system that lets you connect to your PC from anywhere in the world with an Internet connection. All you need is a physical device that you can use as a window into your cloud PC and you are good to go. Getting your head around using a PC in the cloud can take some time. It reminds us of the first time we saw the movie The Matrix. In other words, it can be a bit of a mind trip. You are using a physical computer, and then connecting to your cloud PC, and then using your physical computer just like it is your cloud PC. But your cloud PC lives and runs in the cloud, and your physical computer, any physical computer, is just something real you use to connect to your cloud PC and get work done. Like we said, it can take some time to get your head around it.

View Cheat Sheet
HTML5 How to Create Definition Lists in HTML5

Article / Updated 08-11-2022

Lists are powerful tools for grouping similar elements, and lists give visitors to your site an easy way to zoom in on groups of information. Just about anything fits in a list, from sets of instructions to collections of links. Definition lists group terms and definitions into a single list and require three elements to complete the list: : Holds the list definitions (dl = definition list) : Defines a term in the list (dt = definition term) : Defines a definition for a term (dd = definition list definition) You can have as many terms (defined by ) in a list () as you need. Each term can have one or more definitions (defined by ). Creating a definition list with two items requires tags and content in the following order: First term name Content for the definition of the first item Second term name Content for the definition of the second item The following definition list includes three terms, one of which has two definitions: Definition Lists Markup Language Definitions SGML The Standard Generalized Markup Language HTML The Hypertext Markup Language The markup language you use to create web pages. XML The Extensible Markup Language The figure shows how a browser displays this HTML. If you think items in a list are too close together, you can use CSS styles to carefully control all aspects of list appearance. Note that definition lists often display differently inside different browsers, and they aren’t always handled the same by search engines or text-to-speech translators. About.com has a nice discussion of definition lists on their Web Design / HTML page. Alas, this means that definition lists may not be the best choice of formatting for lists you create (even lists of definitions). For a more detailed discussion, see the excellent coverage of this topic on Max Design.

View Article
App Development 9 SwiftUI Tips and Tricks

Article / Updated 08-10-2022

SwiftUI makes creating your iOS applications easy and efficient. However, there are neat tricks that are not so obvious. Here, you learn some of these tips and tricks so that you can become a better SwiftUI developer. Resume SwiftUI’s live preview My number-one pet peeve about SwiftUI is that the live preview feature in Xcode doesn’t always work. Very often, changes made to your code will cause the automatic previewing feature to pause. Even though your code is perfectly correct and there is no error, the live preview just can’t seem to update automatically. Of course, you could click the Resume button to update the preview, but you waste precious time moving your mouse to click the button. A better way is to press ⌘+Option+P. This causes the live preview to resume and update itself. Now that you know this trick, there is no reason to click the Resume button anymore! You may also want to check out the list of shortcuts for working in Xcode. Combine text views in SwiftUI Here is a neat little trick that you should know if you want to display the various words in a sentence in different colors and sizes. Instead of using the HStack view to group various Text views together, you can simply use the plus (+) operator to add different Text views together, like this: struct ContentView: View { var body: some View { Text("Red ") .foregroundColor(.red) .font(.largeTitle) + Text("Green ") .foregroundColor(.green) .font(.body) + Text("Blue") .foregroundColor(.blue) .font(.title) } } How cool is that? Here’s the output. If you want all the texts to be of the same font size, group them together using a Group view and apply the font() modifier on the Group view: struct ContentView: View { var body: some View { Group { Text("Red ") .foregroundColor(.red) + Text("Green ") .foregroundColor(.green) + Text("Blue") .foregroundColor(.blue) } .font(.largeTitle) } } Create custom modifiers in SwiftUI Swift modifiers allow you to change the behaviors of views. Consider the following example: import SwiftUI struct ContentView: View { var body: some View { VStack { Text("Leonardo da Vinci") .bold() .font(.largeTitle) .foregroundColor(.blue) .shadow(radius: 2) Text("Vincent van Gogh") .bold() .font(.largeTitle) .foregroundColor(.blue) .shadow(radius: 2) } } } Here, you apply the same set of modifiers to the two Text views. You often do that when you want to ensure consistencies in your UI (for example, applying the same set of UI styles when displaying certain information in your application). Instead of repeating the same set of modifiers again and again, wouldn’t it be easier if you could just encapsulate all the modifiers into yet another modifier? What you can do it is create another struct that conforms to the ViewModifier protocol. This protocol requires you to implement a body() method that has a Content parameter. You then apply whatever modifiers you want to this Content argument and return it: import SwiftUI struct Title: ViewModifier { func body(content: Content) -> some View { content .font(.largeTitle) .foregroundColor(.blue) .shadow(radius: 2) } } To use the newly created Title struct on the Text view, apply the modifier() modifier and pass in the Title struct, like this: struct ContentView: View { var body: some View { VStack { Text("Leonardo da Vinci") .bold() .modifier(Title()) Text("Vincent van Gogh") .bold() .modifier(Title()) } } } To make the Title struct look more like a true modifier, create an extension to the View protocol and give it a name — say, titleStyle: import SwiftUI extension View { func titleStyle() -> some View { self.modifier(Title()) } } You can now apply the titleStyle() modifier to the two Text views: struct ContentView: View { var body: some View { VStack { Text("Leonardo da Vinci") .bold() .titleStyle() Text("Vincent van Gogh") .bold() .titleStyle() } } } Display multiple alerts in SwiftUI Usually, in SwiftUI you apply a single alert() modifier to a single view. For example, when the user taps a button, you can display an alert by using the alert() modifier to the button. If you have multiple buttons, you can attach an alert() modifier to each button. However, there are times when you need to display multiple different alerts for a single view. Applying multiple alert() modifiers to a single view will not work correctly, because the last modifier will override the earlier ones. To solve this problem, you can use a single alert() modifier, and use a switch statement within the modifier to decide which alert to display. The following example shows a button that, when it’s clicked, generates a random number of either 1 or 2 and uses it to decide which alert to display: struct ContentView: View { @State private var displayAlert = false @State private var alertToDisplay = 0 var body: some View { Button(action: { self.alertToDisplay = Int.random(in: 1..<3) self.displayAlert = true }) { Text("Display Alert") } .alert(isPresented: $displayAlert) { switch alertToDisplay { case 1: return Alert(title: Text("Alert 1"), message: Text("This is Alert 1")) default: return Alert(title: Text("Alert 2"), message: Text("This is Alert 2")) } } } } Enable debug preview in SwiftUI By default, the preview canvas doesn’t display outputs printed using the print() function. This isn’t useful, however, because often you want to use the print() function as a quick debugging option. The good news is, you can easily fix this. In the preview canvas, right-click the Play button and select Debug Preview. Now if you tap the button, your code will print the output in the Output window: struct ContentView: View { var body: some View { Button ("Tap Me") { print("Button was tapped...") } } } If the Output window is not shown in Xcode, press ⌘+Shift+C and it should appear. Preview your SwiftUI app using different devices You’re familiar with using the preview canvas to preview your app. By default, Xcode automatically picks an appropriate device based on your target. You can preview your app on different modes — light mode and dark mode — using the environment() modifier: struct ContentView_Previews: PreviewProvider { static var previews: some View { Group { ContentView() .environment(\.colorScheme, .light) ContentView() .environment(\.colorScheme, .dark) } } } In addition to previewing in different modes, you can alter the size of the preview window, allowing you to have a glimpse of how your UI will look under different screen dimensions. You can do so using the previewLayout() modifier: static var previews: some View { Group { ContentView() .environment(\.colorScheme, .light) .previewLayout((.fixed(width: 400, height: 600))) ContentView() .environment(\.colorScheme, .dark) } } The image below shows the top preview displaying your UI in a dimension of 400 x 600 pixels. Note that clicking the Live Preview button will revert the preview back to the default size. If you want to preview your UI on multiple devices, you can use a ForEach loop, supply a list of device names, and then use the previewDevice() modifier on the ContentView, like this: static var previews: some View { ForEach(["iPhone 11", "iPhone SE"], id: \.self) { deviceName in ContentView() .environment(\.colorScheme, .light) .previewDevice(PreviewDevice( rawValue: deviceName)) .previewDisplayName(deviceName) } } The following image shows the preview on the iPhone 11 and the iPhone SE. Notice that you can display the name of the device using the previewDisplayName() modifier. Check out the full list of devices that you can preview. Dark mode only works on NavigationView As stated, you can use the environment() modifier to set the preview to dark mode so that you can see how your UI will look like in dark mode. However, it seems like the dark preview mode only works for the NavigationView. For example, consider the following example where you have two Text views contained within a VStack view: import SwiftUI struct ContentView: View { var body: some View { VStack { Text("Leonardo da Vinci") Text("Vincent van Gogh") } } } Suppose you use the environment() modifier to set the preview mode to dark, like this: struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() .environment(\.colorScheme, .dark) } } The words in the Text views automatically change to white, but the background remains white (running on the simulator or an actual device doesn’t have this issue), as shown below. So, essentially, you get a white screen. To fix this problem, wrap the ContentView view using a ZStack and set its background to black, like this: struct ContentView_Previews: PreviewProvider { static var previews: some View { ZStack { Color(.black) ContentView() } .edgesIgnoringSafeArea(.all) .environment(\.colorScheme, .dark) } } The image below shows the text showing up on a black background. Extract subviews in SwiftUI Your UI may contain quite a large number of views. This is very common if you have a complicated UI. However, you can simplify your UI by extracting some of the views as subviews. Consider the following example: import SwiftUI struct ContentView: View { var body: some View { HStack { Image("weimenglee") .resizable() .frame(width: CGFloat(120), height: CGFloat(120)) .cornerRadius(CGFloat(15), antialiased: true) VStack { Text("Wei-Meng Lee") .font(.largeTitle) .bold() Text("Founder") Text("Developer Learning Solutions") .italic() Text("http://calendar.learn2develop.net") Text("@weimenglee") } } } } To break down the UI into smaller subviews so that your UI is more modular and manageable, follow these steps: In the preview canvas, select the Image view and press the ⌘ key. Select Extract Subview. Name the new view PhotoView. The Image view will now be extracted as a new struct named PhotoView: struct ContentView: View { var body: some View { HStack { PhotoView() VStack { Text("Wei-Meng Lee") .font(.largeTitle) .bold() Text("Founder") Text("Developer Learning Solutions") .italic() Text("http://calendar.learn2develop.net") Text("@weimenglee") } } } } struct PhotoView: View { var body: some View { Image("weimenglee") .resizable() .frame(width: CGFloat(120), height: CGFloat(120)) .cornerRadius(CGFloat(15), antialiased: true) } } You can now also extract the VStack and save it as another struct named DetailsView. Now your UI looks like the following, which is more maintainable: struct ContentView: View { var body: some View { HStack { PhotoView() DetailsView() } } } struct PhotoView: View { ... } struct DetailsView: View { var body: some View { VStack { Text("Wei-Meng Lee") .font(.largeTitle) .bold() Text("Founder") Text("Developer Learning Solutions") .italic() Text("http://calendar.learn2develop.net") Text("@weimenglee") } } } Display a context menu in SwiftUI One of the innovative features of iPhone is the support for Haptic Touch (which replaces the 3D Touch on older iPhones). Using Haptic Touch, you can long-press an item on your iPhone and a context-sensitive menu appears (if the app you’re using supports it). You can support this feature in SwiftUI as well. To attach a context menu to a view, use the contextMenu() modifier: To attach a context menu to a view, use the contextMenu() modifier: struct ContentView: View { var body: some View { Image("Mac Pro") .resizable() .frame(width: 300, height: 280) .contextMenu { Button(action: { print("Save Image button tapped...") }) { Text("Save Image") Image(systemName: "tray.and.arrow.down") } Button(action: { print("Add to Cart button tapped...") }) { Text("Add to Cart") Image(systemName: "plus") } } } } To create a context menu, you provide a list of Button views, and the content of each button is automatically wrapped using an HStack view. Now when you long-press the Image view, a context menu appears. Want to learn more? Check out our SwifUI Cheat Sheet.

View Article
App Development What Is Swift Programming? Understanding What SwiftUI Is

Article / Updated 08-10-2022

SwiftUI is a declarative programming framework for developing UIs for iOS, iPadOS, watchOS, tvOS, and macOS applications. In fact, SwiftUI was invented by the watchOS group at Apple. Before SwiftUI was introduced, most developers use UIKit and Storyboard (which is still supported by Apple in the current version of Xcode to design a UI. Using UIKit and Storyboard, developers drag and drop View controls onto View Controllers and connect them to outlets and actions on the View Controller classes. This model of building UIs is known as Model View Controller (MVC), which creates a clean separation between UI and business logic. The following shows a simple implementation in UIKit and Storyboard. Here, a Button and Label view have been added to the View Controller in Storyboard; two outlets and an action have been created to connect to them: class ViewController: UIViewController { @IBOutlet weak var lbl: UILabel! @IBOutlet weak var button: UIButton! @IBAction func btnClicked(_ sender: Any) { lbl.text = "Button tapped" } For laying out the views, you use auto-layout to position the button and label in the middle of the screen (both horizontally and vertically). To customize the look and feel of the button, you can code it in the loadView() method, like this: override func loadView() { super.loadView() // background color button.backgroundColor = UIColor.yellow // button text and color button.setTitle("Submit", for: .normal) button.setTitleColor(.black, for: .normal) // padding button.contentEdgeInsets = UIEdgeInsets( top: 10, left: 10, bottom: 10, right: 10) // border button.layer.borderColor = UIColor.darkGray.cgColor button.layer.borderWidth = 3.0 // text font button.titleLabel!.font = UIFont.systemFont(ofSize: 26, weight: UIFont.Weight.regular) // rounder corners button.layer.cornerRadius = 10 // auto adjust button size button.sizeToFit() } The following image shows the button that has customized. UIKit is an event-driven framework, where you can reference each view in your view controller, update its appearance, or handle an event through delegates when some events occurred. In contrast, SwiftUI is a state-driven, declarative framework. In SwiftUI, you can implement all the above with the following statements: struct ContentView: View { @State private var label = "label" var body: some View { VStack { Button(action: { self.label = "Button tapped" }) { Text("Submit") .padding(EdgeInsets( top: 10, leading: 10, bottom: 10, trailing: 10)) .background(Color.yellow) .foregroundColor(Color.black) .border(Color.gray, width: 3) .font(Font.system(size: 26.0)) .overlay( RoundedRectangle(cornerRadius: 10) .stroke(Color.gray, lineWidth: 5) ) } Text(label) .padding() } } } Notice that all the views are now created declaratively using code — no more drag-and-drop in Storyboard. Layouts are now also specified declaratively using code (the VStack in this example stacks all the views vertically). Delegates are now replaced with closures. More important, views are now a function of state (and not a sequence of events) — the text displayed by the Text view is now bound to the state variable label. When the button is tapped, you change the value of the label state variable, which automatically updates the text displayed in the Text view. This programming paradigm is known as reactive programming. The image below shows the various views in action. Want to learn more? Check out our SwiftUI Cheat Sheet.

View Article
App Development A Quick Intro to Swift Functions

Article / Updated 08-10-2022

Are you ready to build iOS apps using an innovative and intuitive user interface? Then, SwiftUI is for you! But before you dive in, you’ll need to know about Swift functions. Here’s a quick intro. In Swift, a function is defined using the func keyword, like this: func doSomething() { print("doSomething") } The preceding code snippet defines a function called doSomething. It does not take in any inputs (known as parameters) and does not return a value (technically, it does return a Void value). To call the function, simply call its name followed by a pair of empty parentheses: doSomething() Understanding input parameters A function can also optionally define one or more named typed inputs. The following function takes in one single typed input parameter: func doSomething(num: Int) { print(num) } To call this function, call its name and pass in an integer value (known as an argument) with the parameter name, like this: doSomething(num: 5) The following function takes in two input parameters, both of type Int: func doSomething(num1: Int, num2: Int) { print(num1, num2) } To call this function, pass it two integer values as the argument: doSomething(num1: 5, num2: 6) Returning a value Functions are not required to return a value. However, if you want the function to return a value, use the -> operator after the function declaration. The following function returns an integer value: func doSomething(num1: Int, num2: Int, num3: Int) -> Int { return num1 + num2 + num3 } You use the return keyword to return a value from a function and then exit it. When the function returns a value, you can assign it to a variable or constant, like this: var sum = doSomething(num1:5, num2:6, num3: 7) Functions are not limited to returning a single value. In some cases, it’s important for functions to return multiple values (or even functions). In Swift, you can use a tuple type in a function to return multiple values. Want to learn more? Check out these SwiftUI tips and tricks.

View Article
YouTube Understanding Your YouTube Channel Audience

Article / Updated 08-10-2022

Video reports and audience retention graphs are designed to help you understand how well your viewers are responding to your YouTube channel content. To find out who’s watching your YouTube videos, you have to try a different tack: check out YouTube’s audience reports. Diving into YouTube’s demographics metrics It helps to know who’s watching your YouTube content so that you can make important content-planning decisions. The Audience tab of YouTube Analytics is a fascinating way to analyze your channel demographics, because you can get concrete information about your audience members’ gender, age, and country of residence. Certain audience reports allow you to filter to see results explicitly from your subscriber base. Sometimes, it’s interesting to see whether your subscriber demographics mirror your general audience demographics. To access audience reports, follow these steps: Go to YouTube. Log on to your YouTube account.If you see the blue Sign In button in the top right corner of the YouTube home page, enter your email address and password. Click the Logged-In icon and choose YouTube Studio from the menu that appears.The YouTube Studio navigation menu should appear on the left side of your browser. Choose Analytics from the navigation menu. Click to open the Audience tab on the Reports menu.Here you find summary reports of age and gender. Click the See More link at the bottom of the Age and Gender summary report, and examine the charts and their accompanying details.It’s terrific if your audience is exactly what you thought it would be. If it isn’t, revisit your assumptions. You may find that your content is having wider interest, which may be a good thing. Conversely, if you’re not seeing enough traction, perhaps you’re not engaging enough with key creators and fans in your core demographic to help you get the word out. Refine the report to show only subscribed viewers by choosing Subscription Status from the filter drop-down menu.Look closely at how the graphs change. If you see a big difference, determine whether subscription requests are working more broadly than expected, because your content certainly is appealing to others. Make it a habit to compare your demographic information over time to detect any shifts in your audience. Diving into YouTube subscribers metrics Knowing your YouTube subscribers’ patterns and where they’re doing their subscribing is an important part of your channel management responsibilities. YouTube is well aware of that, which is why it offers a subscription source report as part of YouTube Analytics. Here’s how to access it: Go to YouTube. Log on to your YouTube account.If you see the blue Sign In button in the top right corner of the YouTube home page, enter your email address and password. Click the Logged-In icon and choose YouTube Studio from the menu that appears.The YouTube Studio navigation menu should appear on the left side of your browser. Bring up the Analytics section of YouTube Studio. Click on Advanced Mode from the top right of the screen.Within the Advanced Mode window, click on More from the Reports menu and find the Subscription Source option. Look at the report’s table section to see where on YouTube your audience subscribes to your channel.In addition to subscriber gains, you see the number of subscribers lost, too, which is a normal part of channel activity. Interested in learning more? Check out our YouTube Channels Cheat Sheet.

View Article
App Development A Brief Primer on Swift Programming: Basic Syntax

Article / Updated 08-10-2022

Swift is a type-safe language, which means that the programming language makes it clear to you the types of values your code is working with. The following article discusses how to declare constants and variables and how to work with strings and comments when programming with Swift. Swift constants In Swift, you create a constant using the let keyword: let radius = 3.45 // Double let numOfColumns = 5 // Int let myName = "Wei-Meng Lee" // String Notice that there is no need to specify the data type — the data types are inferred automatically. If you want to declare the type of constant, you can do so using the colon operator (:) followed by the data type, as shown here: let diameter:Double = 8 After a constant is created, you can no longer change its value. Always use a let when you need to store values that do not change. Swift variables To declare a variable, you use the var keyword: var myAge = 25 var circumference = 2 * 3.14 * radius After a variable is created, you can change its value. In Swift, values are never implicitly converted to another type. For example, suppose you’re trying to concatenate a string and the value of a variable. In the following example, you need to explicitly use the String() function to convert the value of myAge to a string value before concatenating it with another string: var strMyAge = "My age is " + String(myAge) To get the text representation of a value (constant or variable), you can also use the description property, like this: myAge.description. Swift strings One of the common tasks in programming is inserting values of variables into a string. In Swift, you use string interpolation and it has the following format: "Your string literal \(variable_name)" The following statement shows an example: let firstName = "Wei-Meng" let lastName = "Lee" var strName = "My name is \(firstName) \(lastName)" You can also use this method to include a Double value in your string (or even perform mathematical operations or function calls): var strResult = "The circumference is \(circumference)" Swift comments In Swift, as in most programming languages, you insert comments into your code using two forward slashes (//): // this is another comment If you have several lines of comments, it’s better to use the /* and */ combination to denote a block of statements as comments: /* this is a comment this is another comment */ Want to learn more? Check out our SwiftUI Cheat Sheet.

View Article
App Development Swift Closures

Article / Updated 08-10-2022

One important feature in Swift is closure. Closures are self-contained blocks of code that can be passed to functions to be executed as independent code units. Think of a closure as a function without a name. In fact, functions are actually special cases of closures. Swift offers various ways to optimize closures so that they’re brief and succinct. The various optimizations include the following: Inferring parameter types and return types Implicit returns from single-statement closures Shorthand argument names Trailing closure syntax Operator closure Understanding Swift closures The best way to understand Swift closures is to use an example. Suppose you have the following array of integers: let numbers = [5,2,8,7,9,4,3,1] Assume you want to sort this array in ascending order. You could write your own function to perform the sorting, or you could use the sorted() function available in Swift. The sorted() function takes two arguments: An array to be sorted A closure that takes two arguments of the same type as the array and returns a true if the first value appears before the second value Using Swift functions as closures In Swift, functions are special types of closures. As mentioned, the sorted() function needs a closure that takes two arguments of the same type as the array, returning a true if the first value appears before the second value. The following Swift function fulfils that requirement: func ascending(num1:Int, num2:Int) -> Bool { return num1 The ascending() function takes two arguments of type Int and returns a Bool value. If num1 is less than num2, it returns true. You can now pass this function to the sorted() function, as shown here: var sortedNumbers = numbers.sorted(by: ascending) The sorted() function now returns the array that is sorted in ascending order. The sorted() function does not modify the original array. It returns the sorted array as a new array. Assigning Swift closures to variables As mentioned earlier, functions are special types of closures. In fact, a closure is a function without a name. However, you can assign a closure to a variable — for example, the ascending() function discussed earlier can be written as a closure assigned to a variable: var compareClosure : (Int, Int)->Bool = { (num1:Int, num2:Int) -> Bool in return num1 < num2 } To use the compareClosure closure with the sorted() function, pass in the compareClosure variable: sortedNumbers = numbers.sorted(by: compareClosure) Writing Swift closures inline You can pass a function into the sorted() function as a closure function, but a better way is to write the closure inline, which obviates the need to define a function explicitly or assign it to a variable. Rewriting the earlier example would yield the following: sortedNumbers = numbers.sorted(by: { (num1:Int, num2:Int) -> Bool in return num1 < num2 } ) As you can see, the ascending() function name is now gone; all you’ve supplied is the parameter list and the content of the function. If you want to sort the array in descending order, you can simply change the comparison operator: sortedNumbers = numbers.sorted(by: { (num1:Int, num2:Int) -> Bool in return num1 > num2 } ) Understanding type inference Because the type of the first argument of the closure function must be the same as the type of array you’re sorting, it’s actually redundant to specify the type in the closure, because the compiler can infer that from the type of array you’re using: var fruits = ["orange", "apple", "durian", "rambutan", "pineapple"] print(fruits.sorted(by: { (fruit1, fruit2) in return fruit1 If your closure has only a single statement, you can even omit the return keyword: print(fruits.sorted(by: { (fruit1, fruit2) in fruit1 Using shorthand argument names Above, names were given to arguments within a closure. In fact, this is also optional, because Swift automatically provides shorthand names to the parameters, which you can refer to as $0, $1, and so on. The previous code snippet could be rewritten as follows without using named parameters: print(fruits.sorted(by: { $0<$1 }) ) To make the closure really terse, you can write everything on one line: print(fruits.sorted(by:{ $0<$1 })) Working with Swift’s operator function You saw that the closure for the sorted() function was reduced to the following: print(fruits.sorted(by:{ $0<$1 })) One of the implementations of the lesser than (<) operator is actually a function that works with two operands of type String. Because of this, you can actually simply specify the < operator in place of the closure, and the compiler will automatically infer that you want to use the particular implementation of the < operator. The preceding statement can be reduced to the following: print(fruits.sorted(by:<)) If you want to sort the array in descending order, simply use the greater than (>) operator: print(fruits.sorted(by:>)) Using trailing closures in Swift Consider the closure that you saw earlier: print(fruits.sorted(by: { (fruit1, fruit2) in return fruit1 Notice that the closure is passed in as a second argument of the sorted() function. For long closures, this syntax may be a little messy. If the closure is the final argument of a function, you can rewrite this closure as a trailing closure. A trailing closure is written outside of the parentheses of the function call. The preceding code snippet, when rewritten using the trailing closure, looks like this: print(fruits.sorted() { (fruit1, fruit2) in return fruit1 Using the shorthand argument name, the closure can be shortened to the following: print(fruits.sorted(){$0<$1}) Want to learn more? Check out our SwiftUI Cheat Sheet.

View Article
App Development Understanding How to Animate in SwiftUI

Article / Updated 08-10-2022

To animate a view in SwiftUI, apply the animation() modifier on it. SwiftUI animates any changes made to animatable properties of a view. For example, the various properties of a view in SwiftUI — such as its color, opacity, rotation, size, and other properties — are all animatable. As usual, the best way to understand this concept is to use an example. First, create a rounded button that shows the Confirm caption: struct ContentView: View { var body: some View { Button(action: { }) { Text("Confirm") .bold() } .padding(40) .background(Color.green) .foregroundColor(.white) .clipShape(Circle()) } } Apply some scaling (zooming) to the button using the scaleEffect() modifier: struct ContentView: View { @State private var scaleFactor: CGFloat = 1 var body: some View { Button(action: { }) { Text("Confirm") .bold() } .onAppear(perform: { self.scaleFactor = 2.5 }) .padding(40) .background(Color.green) .foregroundColor(.white) .clipShape(Circle()) .scaleEffect(scaleFactor) } } What you want to do here is zoom the button to two and a half times its original size. The scaling will be performed as soon as the Button view is shown in SwiftUI. The following image shows the button zoomed in to two and a half times its original size when it first appears. What you really want is to slow down the scaling, so that users can see the zooming-in process. For this, you can use the animation() modifier on the Button view: struct ContentView: View { @State private var scaleFactor: CGFloat = 1 var body: some View { Button(action: { }) { Text("Confirm") .bold() } .onAppear(perform: { self.scaleFactor = 2.5 }) .padding(40) .background(Color.green) .foregroundColor(.white) .clipShape(Circle()) .scaleEffect(scaleFactor) .animation(.default) } } The .default property actually belongs to the Animation struct, so you can rewrite the above statement as follows: .animation(Animation.default) When you now load the Button view again, the button zooms in two and a half times. Specifying the type of animation in SwiftUI By default, the button will zoom in at a linear speed. You can also use the easeInOur() modifier if you want the animation to start slow, pick up speed, and then slow down again: .animation( .easeInOut(duration: 2) ) The duration parameter indicates how much time is given for the animation to complete in SwiftUI. In this example, the zoom animation must complete in two seconds. If you want to start fast and then slow down, use the easeOut() modifier: .animation( .easeOut(duration: 2) ) Both the easeInOut() and easeOut() modifiers are type methods of the Animation struct. Repeating the animation in SwiftUI Many times, you want the animation to repeat a number of times. For this you can apply the repeatCount() modifier: .animation( Animation.easeInOut(duration: 2) .repeatCount(2, autoreverses: true) ) The easeInOut() is a type method of the Animation struct, and it returns an Animation struct. So, in this case, you call the repeatCount() modifier of the Animation struct to repeat the animation a number of times (twice, in this case). The autoreverses parameter allows you to reverse the animation, so for this particular case the size of the button changes from small to big, and then reverses and changes from big to small. The image below shows the animation that is repeated twice. Notice that at the end of the second animation, the button reverts back to the larger size as specified in the scaleFactor state variable: .scaleEffect(scaleFactor) // changed to 2.5 in onAppear() If you want the animation to repeat forever, use the repeatForever() modifier: .animation( Animation.easeInOut(duration: 2) .repeatForever(autoreverses: true) ) Stopping the animation in SwiftUI Although you can animate nonstop in SwiftUI, there are times where you need to stop the animation. Here’s another example: struct ContentView: View { @State private var opacity:Double = 1.0 var body: some View { Button(action: { }) { Text("Click Me") .fontWeight(.bold) .font(.title) .foregroundColor(.blue) .padding() .background(Color.yellow) .overlay( Rectangle() .stroke(Color.blue, lineWidth: 5) ) .opacity(opacity) .onAppear() { let baseAnimation = Animation.linear(duration: 1) withAnimation ( baseAnimation.repeatForever( autoreverses: true)) { self.opacity = 0.2 } } } } } The preceding code snippet shows a Button view with its opacity initially set to 1.0. When it appears, you perform a linear animation (animating with constant speed) to change the opacity of the button down to 0.2, all within a duration of 1 second. In the next 1 second, it then changes to fully opaque again. Unlike the earlier example, this example does not use the animation() modifier for animation. Instead, you use the withAnimation block. The withAnimation block lets you explicitly tell SwiftUI what to animate. The image below shows the button fully opaque when it’s loaded and then gradually changes its opacity to 0.2. The animation is perpetual, so to stop it, you need to do some work in SwiftUI. For this, you can use a Boolean state variable (let’s call it animate) and use it to determine if the animation should continue: withAnimation (self.animate ? baseAnimation.repeatForever( autoreverses: true) : Animation.default) { self.opacity = 0.2 } In the preceding Swift code snippet, if the animate state variable is true, you’ll perform the animation perpetually, or you can set the animation to default (which will only perform the animation once). The following code snippet stops the animation when the button is tapped and sets the opacity of the button back to 1: struct ContentView: View { @State private var opacity:Double = 1.0 @State private var animate = true var body: some View { Button(action: { self.animate = false self.opacity = 1.0 }) { Text("Click Me") .fontWeight(.bold) .font(.title) .foregroundColor(.blue) .padding() .background(Color.yellow) .overlay( Rectangle() .stroke(Color.blue, lineWidth: 5) ) .opacity(opacity) .onAppear() { let baseAnimation = Animation.linear(duration: 1) withAnimation (self.animate ? baseAnimation.repeatForever( autoreverses: true) : Animation.default) { self.opacity = 0.2 } } } } } Remember to follow the Apple Human Interface Guidelines (HIG) when it comes to animating your UI. This also applies to custom animations. Want to learn more? Check out these SwiftUI resources.

View Article
SketchUp 10 SketchUp Issues and Their Workarounds

Article / Updated 08-10-2022

The bad news is that every new SketchUp user encounters certain problems, usually in the first couple hours of using the software. You can call these problems growing pains. The good news is that, because these SketchUp problems are common, you can anticipate a lot of the bad stuff you’ll go through. This article offers you SketchUp tips and tricks to help you work around those issues. SketchUp won’t create a face where you want it to You’ve dutifully traced all around where you want SketchUp to create a face, but nothing’s happening. If you follow along in the image below, which was inspired by a visit to the M.C. Escher museum in Amsterdam, you see the top-left image seems to show a cube beside a rectangle, but the rectangle didn’t produce a face. In the top-right image, a diagonal line was drawn between diagonally opposite corners of the rectangle, producing two triangular faces, but something still doesn’t look right. Changing the camera position to standard front (lower-left image) and right side (lower-right image) reveals the source of the problem. It turns out that the upper-right corner of the rectangle doesn’t lie on the red-blue plane but is actually to the right of the blue-green plane, and to the right of the blue-red plane. The upper-left image isn’t really an optical illusion; it just looks like one. Ninety percent of the time, when SketchUp doesn’t create a face where you think it should, an edge isn’t on the plane you think it’s on. To check whether your edges are coplanar, draw an edge that cuts diagonally across the area where you want a face to appear. If a face appears now, your edges aren’t all on the same plane. To fix the problem, you have to figure out which edge is the culprit, and the Color By Axis option may help you see this information at a glance. Here’s how Color By Axis works: In the Styles panel, change your edge color from All Same to By Axis.SketchUp draws the edges in your model using the color of the axis to which they’re parallel; edges parallel to the red axis are red, and so on. Look carefully at the edges that you wanted to define your desired face.Are all the edges the color they’re supposed to be? If they’re not all supposed to be parallel to the drawing axes, this technique doesn’t do much good. But if they are, and one (or more) of them is black (instead of red or green or blue), that edge (or those edges) is your problem child. Fix it and switch back to All Same when you’re done. If the plane isn’t the problem with your edges, then check whether one edge is part of a separate group or component. To check whether you have a component problem, try hiding groups or components and checking the edges to make sure that they’re all in the group or component you think they’re in. A common source of this problem is SketchUp’s inferences. As you slide the mouse over a face you may unwittingly be latching on to an unintended inference, such as the edge of a surface that is part of a cylinder. Watch those inference prompts, and use Undo when you complete a face but no face appears. Your SketchUp faces are two different colors In SketchUp, faces have two sides: a front and a back. By default, these two sides are different colors. When you use certain tools, such as Push/Pull or Follow Me, on a face, sometimes the faces on the resulting geometry are “inside out.” For some people, the issue is just bothersome. If you want to 3D-print your model, you need to fix the issue so that your model will print correctly. To fix this issue, right-click the faces you want to flip and choose Reverse Faces from the context menu. If you have lots of faces to flip, you can select them all and then choose Reverse Faces to flip them all at once. In 3D printing, this process is called checking your model’s normals. The plan for the structure you see below was for all the outside walls to be wood siding and the interior walls to be painted yellow. But the top two images show that somehow the left wall got reversed. The bottom two images show that the problem has been solved by selecting the yellow face and reversing it. Edges on a face won’t sink in Edges on a face tend not to sink in when you’re trying to draw a rectangle (or another geometric figure) on a face with one of SketchUp’s shape-drawing tools. Ordinarily, the Rectangle tool creates a new face on top of any face you use it on; after that, you can use Push/Pull to create a hole, if you want. When the edges you just drew don’t seem to cut through the face you drew them on, try these approaches: Retrace one of the edges. Sometimes that works — you’d be surprised how often. Select Hidden Geometry from the View menu. You’re checking to make sure that the face you just drew isn’t crossing any hidden or smoothed edges; if it is, the face you thought was flat may not be. Make sure that the face you drew on isn’t part of a group or component. If it is, undo a few steps and then redraw your shape while you edit the group or component. Select the face + edges, right-click, and choose Intersect Faces→With Selection. This approach is often needed when you are working with one or more curved surfaces. SketchUp crashed, and you lost your model Unfortunately, SketchUp crashes happen sometimes. The good news is that SketchUp automatically saves a copy of your file every five minutes. In the web version, these autosaves are captured in Trimble Connect as revisions. You can always view the revision history for a file by navigating to it in the Trimble Connect tab (by clicking Open in the menu at the top of the screen to access Trimble Connect). For any file, you can choose to view or restore an older version. In desktop versions, the file that SketchUp autosaves is actually a separate file, AutoSave_yourfilename.skp. If your file ever gets corrupted in a crash, an intact file is ready for you. The problem is that most people don’t even know that the autosaved file is there. Where do you find it? If you’ve ever saved your file, the autosaved file is in the same folder as the original; therefore, it’s very important that you save your file almost immediately after starting it. Simple, right? Not so fast. On a Mac, you may need to change your Library folder from hidden to visible. In the Finder app, hold down the Option key while you choose Go→Library. If you don’t hold down the Option key, Library may not appear on the menu. When you close your model, SketchUp typically assumes nothing untoward has happened and usually cleans up after itself by deleting the autosaved file. The really good news is that every time you save a file, SketchUp proactively saves two identical files, one with the normal file extension .SKP and the other with the file extension .SKB. You continue working on the .SKP file. If something goes really wrong with your model, you can always go back to how it was an instant before the last time you saved it. But you can’t find it in the Open File dialog box. Here’s the secret: In the Open File dialog box, go to the end of the File Name window, click the down arrow beside Sketchup Models (.SKP), and click All Files. Now the .SKB files show, and you can open them. (web: The same basic principles apply, but read more details on SketchUp's website.) To minimize the amount of work you lose when software (or hardware) goes south, always do two things: Save often — compulsively, even. Use the Save a Copy As command on the File menu. When you’re working on a big project, the following steps can help ensure you don’t lose any work: Save the original version of your file as yourfilename_Master.skp.That’s the file you’ll always be working on. Create a folder that lives in the same place as your Master file; call the folder something like Your file’s name Archive. Every half-hour or so, choose File→Save a Copy As, and save a sequentially numbered version of your file to the Archive folder.When you’re building a big model, it’s not uncommon for your Archive folder to contain 40 or 50 saved versions of the model dating back to when the project first started. Back up regularly.At least at the end of every work session, such as when you head to a coffee or lunch break, back up your files to a low-cost, high-capacity, high-speed portable USB drive, then remove it and keep it separate from your computer. At the end of your shift, take it to a different location. You don’t need to keep it in a bank vault, just in a separate building. Take it home at night, for example. You can always buy new hardware and software, but you can’t buy your personal files. SketchUp is sooooo slooooooooow The bigger your SketchUp model, the worse your computer’s performance. What makes a model big? In a nutshell, faces. Do everything in your power to keep your model as small as you can. Here are some tips for doing that: Reduce the number of sides on your extruded circles and arcs. Use 2D people and trees instead of 3D ones. 3D plants and people have hundreds of faces each. Consider using 2D ones instead, especially if your model won’t be seen much from overhead. Use search filters in 3D Warehouse. When you’re searching for models in 3D Warehouse, you can restrict your search result to show only models of a certain file size or polygon (face) complexity. Especially if your model is more than 10 MB, it makes sense to keep your 3D Warehouse downloads small! Some models are just big, and you can’t do much about it. Here are some tricks for working with very large SketchUp models: Make liberal use of the Outliner and tags. These SketchUp features were specifically designed to let you organize your model into manageable chunks. Hide everything you’re not working on at the moment; doing so gives your computer a fighting chance. Substitute simple forms for large numbers of complex components. For example, insert sticks as placeholders for big sets of 3D trees, cars, and other big components. Turn off shadows and switch to a simple style, such as Shaded in the Default Styles collection. It takes a lot of computer horsepower to display shadows, edge effects, and textures in real time on your monitor. When you’re working, turn off all that stuff. Use scenes to navigate between views. Scenes aren’t just for presenting your model; they’re also great for working with it. If you create scenes for the different views you commonly use and with different combinations of hidden geometry, then you don’t have to orbit, pan, and zoom around your gigantic model. To speed up things even more, deselect Enable Scene Transitions in the Animation panel of the Model Info dialog box. (web: Animation settings are in the Scenes panel.) You can’t get a good view of the inside of your SketchUp model It’s not always easy to work on the inside of something in SketchUp. You can do these things to make it easier, though: Cut into your model with section SketchUp’s Sections feature lets you cut away parts of your model — temporarily, of course — so that you can get a better view of what’s inside. Widen your field of view. Field of view is the part of your model you can see onscreen at one time. A wider FOV is like having better peripheral vision. You can change the field of view only when in Perspective view mode, but the setting will be remembered if you then switch to Parallel view mode. The image below shows the plan view of a room. If you zoom or walk in through the door — oops, tunnel vision. Increase peripheral vision by changing your field of view. Ah, that’s better! Now you can see that the picture hanging on the wall is the floor plan of this room. A face flashes when you orbit in SketchUp If you have two faces in the same spot — maybe one is in a separate group or component — you see a Z-fighting effect. SketchUp is deciding which face to display by switching back and forth between them; it’s not a good solution, but certainly a logical one — at least for a piece of software. The image below attempts to portray this effect in a single image. The only way to get rid of Z-fighting is to delete or hide one of the faces. You can’t move your SketchUp component the way you want When you insert some components into your model, the components by default glue to faces. A glued component instance isn’t actually glued in one place. Instead, it’s glued to the plane of the face you originally placed (or created) it on. For example, if you place a sofa component on the floor of your living room, you can move it around only on that plane — not up and down. This gluing behavior comes in handy when you deal with things like furniture; it allows you to rearrange things with the Move tool without accidentally picking them up. If you can’t move your component the way you want to, right-click it to see whether Unglue is an option; if it is, choose it. Now you can move your component around however you want. Bad stuff happens almost every time you use SketchUp’s Eraser When you use the Eraser tool, it’s pretty easy to delete stuff accidentally. Worse, you usually don’t notice what’s missing until it’s too late. Here are some tips for erasing more accurately: Orbit around. Try to make sure that nothing is behind whatever you’re erasing; use SketchUp’s navigation tools to get a view of your model that puts you out of danger. Switch on Back Edges. When you’re doing a lot of erasing, choose View→Edge Style→Back Edges. That way, you can see every edge in your model, and you’re less likely to erase the wrong ones. Use the Undo modifier of the eraser. Follow along starting in the upper-left image you see below. The intent is to erase the four edges in the center to create a single face. While erasing, you can select multiple objects by holding down the left mouse button while dragging the eraser over them. Oh, great googly moogly (or words to that effect) — you selected some things you didn’t want to erase. No problem: Don’t release the mouse button, but press and hold down the keyboard Alt key (Mac: ⌘). Now anything you drag the eraser over will be unselected. You can switch back and forth as desired, but nothing actually gets erased until you release the mouse button. Double-check. After you do a lot of erasing, give your model a quick once-over with the Orbit tool, just to make sure that you didn’t get rid of anything important. Put a sticky note on your computer monitor that says something like Check after Erase! just to remind you. All your edges and faces have different tags Using Tags in SketchUp can be a dangerous business. Here’s the short version of some good advice: Always build everything on Untagged, and assign whole groups or components to other tags only if you really need to. If you used tags in SketchUp and now things are messed up, here’s what you can do to recover: Make sure that everything is visible.Select Hidden Geometry on the View menu; then (in the Tags panel) make all your tags visible. Just make sure that you can see everything in your model. Choose Edit→Select All. In the Entity Info panel, move everything to Layer0. In the Tags panel, delete your other tags. When you’re prompted, tell SketchUp to move anything remaining on them to Untagged. Create new tags and follow best practices to avoid problems. If you’ve downloaded 3D Warehouse models, you’ll probably find that they have some tags that you don’t understand and might want to get rid of. They may have had significance to the original creator, but they can become clutter in your file, so they should be removed. Want to learn more? Check out our SketchUp Cheat Sheet.

View Article
page 1
page 2
page 3
page 4
page 5
page 6
page 7
page 8
page 9
page 10
page 11
page 12
page 13
page 14
page 15
page 16
page 17
page 18
page 19
page 20
page 21
page 22
page 23
page 24
page 25
page 26
page 27
page 28
page 29
page 30
page 31
page 32
page 33
page 34
page 35
page 36
page 37
page 38
page 39
page 40
page 41
page 42
page 43
page 44
page 45
page 46
page 47
page 48
page 49
page 50
page 51
page 52
page 53
page 54
page 55
page 56
page 57
page 58
page 59
page 60
page 61
page 62
page 63
page 64
page 65
page 66
page 67
page 68
page 69
page 70
page 71
page 72
page 73
page 74
page 75
page 76
page 77
page 78
page 79
page 80
page 81
page 82
page 83
page 84
page 85
page 86
page 87
page 88
page 89
page 90
page 91
page 92
page 93
page 94
page 95
page 96
page 97
page 98
page 99
page 100
page 101
page 102
page 103
page 104
page 105
page 106
page 107
page 108
page 109
page 110
page 111
page 112
page 113
page 114
page 115
page 116
page 117
page 118
page 119
page 120
page 121
page 122
page 123
page 124
page 125
page 126
page 127
page 128
page 129
page 130
page 131
page 132
page 133
page 134
page 135
page 136
page 137
page 138
page 139
page 140
page 141
page 142
page 143
page 144
page 145
page 146
page 147
page 148
page 149
page 150
page 151
page 152
page 153
page 154
page 155
page 156
page 157
page 158
page 159
page 160
page 161
page 162
page 163
page 164
page 165
page 166
page 167
page 168
page 169
page 170
page 171
page 172
page 173
page 174
page 175
page 176
page 177
page 178
page 179
page 180
page 181
page 182
page 183
page 184
page 185
page 186
page 187
page 188
page 189
page 190
page 191
page 192
page 193
page 194
page 195
page 196
page 197
page 198
page 199
page 200
page 201
page 202
page 203
page 204
page 205
page 206
page 207
page 208
page 209
page 210
page 211
page 212
page 213
page 214
page 215
page 216
page 217
page 218
page 219
page 220
page 221
page 222
page 223
page 224
page 225
page 226
page 227
page 228
page 229
page 230
page 231
page 232
page 233
page 234
page 235
page 236
page 237
page 238
page 239
page 240
page 241
page 242
page 243
page 244
page 245
page 246
page 247
page 248
page 249
page 250
page 251
page 252
page 253
page 254
page 255
page 256
page 257
page 258
page 259
page 260
page 261
page 262
page 263
page 264
page 265
page 266
page 267
page 268
page 269
page 270
page 271
page 272
page 273
page 274
page 275
page 276
page 277
page 278
page 279
page 280
page 281
page 282
page 283
page 284
page 285
page 286
page 287
page 288
page 289
page 290
page 291
page 292
page 293
page 294
page 295
page 296
page 297
page 298
page 299
page 300
page 301
page 302
page 303
page 304
page 305
page 306
page 307
page 308
page 309
page 310
page 311
page 312
page 313
page 314
page 315
page 316
page 317
page 318
page 319
page 320
page 321
page 322
page 323
page 324
page 325
page 326
page 327
page 328
page 329
page 330
page 331
page 332
page 333
page 334
page 335
page 336
page 337
page 338
page 339
page 340
page 341
page 342
page 343
page 344
page 345
page 346
page 347
page 348
page 349
page 350
page 351
page 352
page 353
page 354
page 355
page 356
page 357
page 358
page 359
page 360
page 361
page 362
page 363
page 364
page 365
page 366
page 367
page 368
page 369
page 370
page 371
page 372
page 373
page 374
page 375
page 376
page 377
page 378
page 379
page 380
page 381
page 382
page 383
page 384
page 385
page 386
page 387
page 388
page 389
page 390
page 391
page 392
page 393
page 394
page 395
page 396
page 397
page 398
page 399
page 400
page 401
page 402
page 403
page 404
page 405
page 406
page 407
page 408
page 409
page 410
page 411
page 412
page 413
page 414
page 415
page 416
page 417
page 418
page 419
page 420
page 421
page 422
page 423
page 424
page 425
page 426
page 427
page 428
page 429
page 430
page 431
page 432
page 433
page 434
page 435
page 436
page 437
page 438
page 439
page 440
page 441
page 442
page 443
page 444
page 445
page 446
page 447
page 448
page 449
page 450
page 451
page 452
page 453
page 454
page 455
page 456
page 457
page 458
page 459
page 460
page 461
page 462
page 463
page 464
page 465
page 466
page 467
page 468
page 469
page 470
page 471
page 472
page 473
page 474
page 475
page 476
page 477
page 478
page 479
page 480
page 481
page 482
page 483
page 484
page 485
page 486
page 487
page 488
page 489
page 490
page 491
page 492
page 493
page 494
page 495
page 496
page 497
page 498
page 499
page 500
page 501
page 502
page 503
page 504
page 505
page 506
page 507
page 508
page 509
page 510
page 511
page 512
page 513
page 514
page 515
page 516
page 517
page 518
page 519
page 520
page 521
page 522
page 523
page 524
page 525
page 526
page 527
page 528
page 529
page 530
page 531
page 532
page 533
page 534
page 535
page 536
page 537
page 538
page 539
page 540
page 541
page 542
page 543
page 544
page 545
page 546
page 547
page 548
page 549
page 550
page 551
page 552
page 553
page 554
page 555
page 556
page 557
page 558
page 559
page 560
page 561
page 562
page 563
page 564
page 565
page 566
page 567
page 568
page 569
page 570
page 571
page 572
page 573
page 574
page 575
page 576
page 577
page 578
page 579
page 580
page 581
page 582
page 583
page 584
page 585
page 586
page 587
page 588
page 589
page 590
page 591
page 592
page 593
page 594
page 595
page 596
page 597
page 598
page 599
page 600
page 601
page 602
page 603
page 604
page 605
page 606
page 607
page 608
page 609
page 610
page 611
page 612
page 613
page 614
page 615
page 616
page 617
page 618
page 619
page 620
page 621
page 622
page 623
page 624
page 625
page 626
page 627
page 628
page 629
page 630
page 631
page 632
page 633
page 634
page 635
page 636
page 637
page 638
page 639
page 640
page 641
page 642
page 643
page 644
page 645
page 646
page 647
page 648
page 649
page 650
page 651
page 652
page 653
page 654
page 655
page 656
page 657
page 658
page 659
page 660
page 661
page 662
page 663
page 664
page 665
page 666
page 667
page 668
page 669
page 670
page 671
page 672
page 673
page 674
page 675
page 676
page 677
page 678
page 679
page 680
page 681
page 682
page 683
page 684
page 685
page 686
page 687
page 688
page 689
page 690
page 691
page 692
page 693
page 694
page 695
page 696
page 697
page 698
page 699
page 700
page 701
page 702
page 703
page 704
page 705
page 706
page 707
page 708
page 709
page 710
page 711
page 712
page 713
page 714
page 715
page 716
page 717
page 718
page 719
page 720
page 721
page 722
page 723
page 724
page 725
page 726
page 727
page 728
page 729
page 730
page 731
page 732
page 733
page 734
page 735
page 736
page 737
page 738
page 739
page 740
page 741
page 742
page 743
page 744
page 745
page 746
page 747
page 748
page 749
page 750
page 751
page 752
page 753
page 754
page 755
page 756
page 757
page 758
page 759
page 760
page 761
page 762
page 763
page 764
page 765
page 766
page 767
page 768
page 769
page 770
page 771
page 772
page 773
page 774
page 775
page 776
page 777
page 778
page 779
page 780
page 781
page 782
page 783
page 784
page 785
page 786
page 787
page 788
page 789
page 790
page 791
page 792
page 793
page 794
page 795
page 796
page 797
page 798
page 799
page 800
page 801
page 802
page 803
page 804
page 805
page 806
page 807
page 808
page 809
page 810
page 811
page 812
page 813
page 814
page 815
page 816
page 817
page 818
page 819
page 820
page 821
page 822
page 823
page 824
page 825
page 826
page 827
page 828
page 829
page 830
page 831
page 832
page 833
page 834
page 835
page 836
page 837
page 838
page 839
page 840
page 841
page 842
page 843
page 844
page 845
page 846
page 847
page 848
page 849
page 850
page 851
page 852
page 853
page 854
page 855
page 856
page 857
page 858
page 859
page 860
page 861
page 862
page 863
page 864
page 865
page 866
page 867
page 868
page 869
page 870
page 871
page 872
page 873
page 874
page 875
page 876
page 877
page 878
page 879
page 880
page 881
page 882
page 883
page 884
page 885
page 886
page 887
page 888
page 889
page 890
page 891
page 892
page 893
page 894
page 895
page 896
page 897
page 898
page 899
page 900
page 901
page 902
page 903
page 904
page 905
page 906
page 907
page 908
page 909
page 910
page 911
page 912
page 913
page 914
page 915
page 916
page 917
page 918
page 919
page 920
page 921
page 922
page 923
page 924
page 925
page 926
page 927
page 928
page 929
page 930
page 931
page 932
page 933
page 934
page 935
page 936
page 937

Quick Links

  • About For Dummies
  • Contact Us
  • Activate A Book Pin

Connect

Opt in to our newsletter!

By entering your email address and clicking the “Submit” button, you agree to the Terms of Use and Privacy Policy & to receive electronic communications from Dummies.com, which may include marketing promotions, news and updates.

About Dummies

Dummies has always stood for taking on complex concepts and making them easy to understand. Dummies helps everyone be more knowledgeable and confident in applying what they know. Whether it's to pass that big test, qualify for that big promotion or even master that cooking technique; people who rely on dummies, rely on it to learn the critical skills and relevant information necessary for success.

Terms of Use
Privacy Policy
Cookies Settings
Do Not Sell My Personal Info - CA Only