{"id":57,"date":"2022-04-10T04:47:15","date_gmt":"2022-04-10T04:47:15","guid":{"rendered":"https:\/\/www.bigbo.at\/?p=57"},"modified":"2022-04-10T04:47:36","modified_gmt":"2022-04-10T04:47:36","slug":"100daysofswiftui-day-20-project-2-part-1","status":"publish","type":"post","link":"https:\/\/www.bigbo.at\/?p=57","title":{"rendered":"100DaysOfSwiftUI &#8211; Day 20 &#8211; Project 2, Part 1"},"content":{"rendered":"\n<p>Today kicked off the <a href=\"https:\/\/www.hackingwithswift.com\/100\/swiftui\/20\">into to Project 2<\/a>. Our fearless teacher <a href=\"https:\/\/twitter.com\/twostraws\">@twostraws<\/a> starts us VStacks, HStacks, and ZStacks. These three Views let us draw multiple views onto the screen in a vertical, horizontal, or depth layout.<\/p>\n\n\n\n<p>After some discussions on colors, we took at look at gradients. This was actually kinda slick. With a tiny amount of code, it\u2019s simple to create a beautiful gradient.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift\">    var body: some View {\n        AngularGradient(gradient: Gradient(colors: [.red, .yellow,\n            .green, .blue, .purple, .red]), center: .center)\n            .ignoresSafeArea()\n    }\n<\/code><\/pre>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/www.bigbo.at\/wp-content\/uploads\/2022\/04\/Screen-Shot-2022-04-10-at-12.12.32-AM.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.bigbo.at\/wp-content\/uploads\/2022\/04\/Screen-Shot-2022-04-10-at-12.12.32-AM.png\" alt=\"\" class=\"wp-image-56\" width=\"188\" height=\"369\"\/><\/a><\/figure><\/div>\n\n\n\n<p>After gradients it was on to buttons and alert messages. Having written iOS apps in Objective-C previously, alerts in SwiftUI were\u2026 different. I just keep telling myself \u201cviews are a function of their state\u201d and that puts my mind at ease. Even if I can\u2019t fully wrap my head around it at the moment.<\/p>\n\n\n\n<p>Here\u2019s an example. Take a look at this Objective-C code I wrote in 2012 (don\u2019t laugh).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"objectivec\" class=\"language-objectivec\">        [[UIAlertView alloc] initWithTitle: @\"Unable to start game\"\n                                   message: @\"Something went wrong.\"\n                                  delegate: self\n                         cancelButtonTitle: @\"OK\"\n                         otherButtonTitles: nil];\n        [alert show];<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Compare that with SwiftUI Alerts<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"swift\" class=\"language-swift\">struct ContentView: View {\n    @State private var showingAlert = false\n    \n    var body: some View {\n\n        Button(\"Danger Alert\"){\n            showingAlert = true\n        }\n        .alert(\"Danger Danger Danger\", isPresented: $showingAlert){\n            Button(\"Cancel\", role: .cancel) {}\n            Button(\"Bye Bye\", role: .destructive) {}\n        } message: {\n            Text(\"Lorem ipsum and all that goes with it\")\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>So yea, in the last 10 years, iOS development has changed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today kicked off the into to Project 2. Our fearless teacher @twostraws starts us VStacks, HStacks, and ZStacks. These three Views let us draw multiple views onto the screen in a vertical, horizontal, or depth layout. After some discussions on colors, we took at look at gradients. This was actually<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[5,7,6,8],"class_list":["post-57","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-100daysofswiftui","tag-code","tag-hackingwithswift","tag-images"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bigbo.at\/index.php?rest_route=\/wp\/v2\/posts\/57","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bigbo.at\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bigbo.at\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bigbo.at\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bigbo.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=57"}],"version-history":[{"count":9,"href":"https:\/\/www.bigbo.at\/index.php?rest_route=\/wp\/v2\/posts\/57\/revisions"}],"predecessor-version":[{"id":66,"href":"https:\/\/www.bigbo.at\/index.php?rest_route=\/wp\/v2\/posts\/57\/revisions\/66"}],"wp:attachment":[{"href":"https:\/\/www.bigbo.at\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=57"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bigbo.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=57"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bigbo.at\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}