<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Barbara Tozier</title>
<link>https://www.barbaratozier.com/posts.html</link>
<atom:link href="https://www.barbaratozier.com/posts.xml" rel="self" type="application/rss+xml"/>
<description>Personal website and blog</description>
<image>
<url>https://www.barbaratozier.com/assets/messy-bee.jpg</url>
<title>Barbara Tozier</title>
<link>https://www.barbaratozier.com/posts.html</link>
</image>
<generator>quarto-1.9.36</generator>
<lastBuildDate>Fri, 05 Jun 2026 04:00:00 GMT</lastBuildDate>
<item>
  <title>100 Days of SwiftUI</title>
  <link>https://www.barbaratozier.com/posts/260605-100-days-of-swiftui-day-46/</link>
  <description><![CDATA[ 

<header id="title-block-header">

<p class="subtitle lead"><a href="https://www.hackingwithswift.com/100/swiftui/46">Day 46</a></p>

<p class="date">2026-06-05</p>
</header>


<section id="project-9-part-4" class="level2">
<h2 class="anchored" data-anchor-id="project-9-part-4">Project 9, part 4</h2>
<p>Navigation wrap up &amp; challenges</p>
<p><strong>Quiz:</strong> 12/12</p>
</section>
<section id="challenges" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="challenges">Challenges</h2>
<blockquote class="blockquote">
<ol type="1">
<li>Change project 7 (iExpense) so that it uses NavigationLink for adding new expenses rather than a sheet. (Tip: The dismiss() code works great here, but you might want to add the navigationBarBackButtonHidden() modifier so they have to explicitly choose Cancel.)</li>
</ol>
</blockquote>
<div class="page-columns page-full"><p>First I restructured the layout so I don’t have to have two separate sections. Then I spent some time figuring out how to color the two sections differently. <em>Then</em> I got some help from the internet with making a hex-color-to-rgb converter. </p><div class="no-row-height column-margin column-container"><span class="margin-aside">Another helper file!!</span></div></div>
<div class="page-columns page-full"><p>I don’t quite understand why I would use <code>NavigationLink</code> when <code>.navigationDestination</code> is there and requires the least amount of changing.  I just replaced <code>.sheet</code> with <code>.navigationDestination</code> and it worked.</p><div class="no-row-height column-margin column-container"><span class="margin-aside">TBH I couldn’t figure out where navLink was supposed to go</span></div></div>
<p>The second part of Challenge 1 is to</p>
<ol type="1">
<li>hide the back button using <code>.navigationBarBackButtonHidden()</code></li>
<li>add a cancel button to the toolbar</li>
</ol>
<p>I added <code>role: .cancel</code> to the cancel button (and <code>role: .confirm</code> to “save”)</p>
<p><img src="https://www.barbaratozier.com/posts/260605-100-days-of-swiftui-day-46/newadd.png" class="postimg img-fluid" alt="Screencap of new add expense screen, with Save and Cancel buttons"><br>
</p>
<blockquote class="blockquote">
<ol start="2" type="1">
<li>Try changing project 7 so that it lets users edit their issue name in the navigation title rather than a separate textfield. Which option do you prefer?</li>
</ol>
</blockquote>
<p>I”m thinking that this is some other “project 7”? But I think it means to move the “Item Name” to the navTitle.</p>
<p>I did it by adding <code>.navigationTitle($name)</code> to the <code>Form</code> (and commenting out the <code>TextField</code>) and I must say I don’t like it very much. Too many clicks! So I put it back 🙃</p>
<blockquote class="blockquote">
<ol start="3" type="1">
<li>Return to project 8 (Moonshot), and upgrade it to use NavigationLink(value:). This means adding Hashable conformance, and thinking carefully how to use navigationDestination().</li>
</ol>
</blockquote>
<p>This one I don’t understand at all. We already use <code>NavigationLink</code>?</p>
<hr>
<p>I’m calling this done, if not complete. This is one of the problems with following long-ago-created tutorials, I can’t ask clarifying questions.</p>


</section>

 ]]></description>
  <category>100 days</category>
  <category>SwiftUI</category>
  <guid>https://www.barbaratozier.com/posts/260605-100-days-of-swiftui-day-46/</guid>
  <pubDate>Fri, 05 Jun 2026 04:00:00 GMT</pubDate>
  <media:content url="https://www.barbaratozier.com/posts/260605-100-days-of-swiftui-day-46/Day46.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>100 Days of SwiftUI</title>
  <link>https://www.barbaratozier.com/posts/260603-100-days-of-swiftui-day-45/</link>
  <description><![CDATA[ 

<header id="title-block-header">

<p class="subtitle lead"><a href="https://www.hackingwithswift.com/100/swiftui/45">Day 45</a></p>

<p class="date">2026-06-03</p>
</header>


<section id="project-9-part-3" class="level2">
<h2 class="anchored" data-anchor-id="project-9-part-3">Project 9, part 3</h2>
<p>More with navigation — customization</p>
<p>(short day today, which is good ’cause I got some other things to do)</p>
<section id="customizing-the-navigation-bar-appearance" class="level3">
<h3 class="anchored" data-anchor-id="customizing-the-navigation-bar-appearance">Customizing the navigation bar appearance</h3>
<ul>
<li>iOS is opinionated about navigation bars, but we can make some adjustments</li>
<li>basically color, visibility, and which modifiers affect which toolbars (of which there are several types)</li>
</ul>
</section>
<section id="placing-toolbar-buttons-in-exact-locations" class="level3">
<h3 class="anchored" data-anchor-id="placing-toolbar-buttons-in-exact-locations">Placing toolbar buttons in exact locations</h3>
<ul>
<li>iOS will put toolbar buttons on the trailing edge of the toolbar by default</li>
<li>you can specify the placement of a <code>ToolbarItem</code>
<ul>
<li>based on position <em>e.g.</em> <code>ToolbarItem(placement: .topBarLeading)</code></li>
<li>or function <code>ToolbarItem(placement: .confirmationAction)</code></li>
</ul></li>
<li>you can group toolbar items using <code>ToolbarItemGroup</code></li>
</ul>
</section>
<section id="making-your-navigation-title-editable" class="level3">
<h3 class="anchored" data-anchor-id="making-your-navigation-title-editable">Making your navigation title editable</h3>
<ul>
<li><code>.inline</code> style navigation titles can be attached to a binding variable which we can access</li>
</ul>


</section>
</section>

 ]]></description>
  <category>100 days</category>
  <category>SwiftUI</category>
  <guid>https://www.barbaratozier.com/posts/260603-100-days-of-swiftui-day-45/</guid>
  <pubDate>Wed, 03 Jun 2026 04:00:00 GMT</pubDate>
  <media:content url="https://www.barbaratozier.com/posts/260603-100-days-of-swiftui-day-45/Day45.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>100 Days of SwiftUI</title>
  <link>https://www.barbaratozier.com/posts/260602-100-days-of-swiftui-day-44/</link>
  <description><![CDATA[ 

<header id="title-block-header">

<p class="subtitle lead"><a href="https://www.hackingwithswift.com/100/swiftui/44">Day 44</a></p>

<p class="date">2026-06-02</p>
</header>


<section id="project-9-part-2" class="level2">
<h2 class="anchored" data-anchor-id="project-9-part-2">Project 9, part 2</h2>
<blockquote class="blockquote">
<p>How to handle programmatic navigation, but also how to load and save navigation paths so you can restore your app’s state</p>
</blockquote>
<section id="programmatic-navigation-with-navigationstack" class="level3">
<h3 class="anchored" data-anchor-id="programmatic-navigation-with-navigationstack">Programmatic navigation with <code>NavigationStack</code></h3>
<ul>
<li>“programmatic navigation” to switch views based solely on code, not on the user doing something in particular</li>
<li>bind a path variable to the <code>NavigationStack</code> (as an array)</li>
<li>call the path in code, including any subpaths</li>
<li>use the modifier <code>navigationDestination()</code></li>
</ul>
<p>You can put the view in the initiator (in this example, a button) and it doesn’t <em>need</em> to be added to the array before using it. I imagine you create the array so you can save state later.</p>
<p>I tried to replace the <code>Int</code> array with a <code>String</code> array but wasn’t entirely successful in doing it without typing the strings in <em>e.g.</em> <code>path = ["string 1", "string 2"]</code></p>
</section>
<section id="navigating-to-different-data-types-using-navigationpath" class="level3">
<h3 class="anchored" data-anchor-id="navigating-to-different-data-types-using-navigationpath">Navigating to different data types using <code>NavigationPath</code></h3>
<ul>
<li>this is for mixed-types of navigation views</li>
<li>you don’t <em>need</em> the array <strong>unless</strong> you intend to keep the path(s)</li>
<li>since you might have, say, <code>String</code>s and <code>Int</code>s in your path, you need to use a special SwiftUI type called <code>NavigationPath</code></li>
<li><code>NavigationPath</code> uses “type erasure” which means it will store different types of items as long as they are <code>Hashable</code></li>
<li>I wonder what <code>Representation.eager</code> means? (It’s internal. It has a <code>.lazy</code> counterpart)</li>
</ul>
<pre><code>You selected the string Hello
Path = NavigationPath_items:
SwiftUl.NavigationPath.(unknown context at $1d36ffa00).Representation.eager([CodableltemBox (Hello)]), subsequentitems: [l, iterationindex: O)</code></pre>
<ul>
<li>unlike the standard array used in the first example (where you could just say <code>path = [56]</code>), you can’t easily talk to the <code>NavigationPath()</code> object.</li>
</ul>
<blockquote class="blockquote">
<p>Cannot assign value of type ‘String’ to type ‘NavigationPath’</p>
</blockquote>
</section>
<section id="how-to-make-a-navigationstack-return-to-its-root-view-programmatically" class="level3">
<h3 class="anchored" data-anchor-id="how-to-make-a-navigationstack-return-to-its-root-view-programmatically">How to make a <code>NavigationStack</code> return to its root view programmatically</h3>
<ul>
<li>too many back buttons? Reset the path to go home &gt; <code>@Binding</code> property wrapper lets us pass an <code>@State</code> property into another view and modify it from there – we can share an <code>@State</code> property in several places, and changing it in one place will change it everywhere.</li>
</ul>
</section>
<section id="how-to-save-navigationstack-paths-using-codable" class="level3">
<h3 class="anchored" data-anchor-id="how-to-save-navigationstack-paths-using-codable">How to save <code>NavigationStack</code> paths using <code>Codable</code></h3>
<ul>
<li>can be done with either the array-style path object or the <code>NavigationPath</code> object</li>
<li>using <code>JSONEncode...</code> etc.</li>
<li>since <code>NavigationPath</code> doesn’t need to have <code>Codable</code> objects (only <code>Hashable</code>), need to check that you can decode it first.</li>
</ul>
<p><span class="break">&nbsp;</span></p>
<p>This is all very theoretical. I can understand why you would be doing this, but the “sandbox” code he’s using to demonstrate it doesn’t really help me understand how I would use it in an app.</p>


</section>
</section>

 ]]></description>
  <category>100 days</category>
  <category>SwiftUI</category>
  <guid>https://www.barbaratozier.com/posts/260602-100-days-of-swiftui-day-44/</guid>
  <pubDate>Tue, 02 Jun 2026 04:00:00 GMT</pubDate>
  <media:content url="https://www.barbaratozier.com/posts/260602-100-days-of-swiftui-day-44/Day44.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>100 Days of SwiftUI</title>
  <link>https://www.barbaratozier.com/posts/260601-100-days-of-swiftui-day-43/</link>
  <description><![CDATA[ 

<header id="title-block-header">

<p class="subtitle lead"><a href="https://www.hackingwithswift.com/100/swiftui/43">Day 43</a></p>

<p class="date">2026-06-01</p>
</header>


<section id="project-9-part-1" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="project-9-part-1">Project 9, part 1</h2>
<div class="page-columns page-full"><p>Learning about (app) navigation. </p><div class="no-row-height column-margin column-container"><span class="margin-aside">Though having a course on celestial navigation might be fun 🤔</span></div></div>
<p>It’s not all <code>NavigationStack</code>!</p>
<section id="the-problem-with-a-simple-navigationlink" class="level3">
<h3 class="anchored" data-anchor-id="the-problem-with-a-simple-navigationlink">The problem with a simple <code>NavigationLink</code></h3>
<p>SwiftUI creates the detail view at the same time it creates the main view. For a simple app with only a couple views this might be ok, but if there are a lot of complicated (dynamically generated) views it might become a problem. A lot of work is being done before it’s needed.</p>
</section>
<section id="handling-navigation-the-smart-way-with-navigationdestination" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="handling-navigation-the-smart-way-with-navigationdestination">Handling navigation the smart way with <code>navigationDestination()</code></h3>
<div class="page-columns page-full"><p></p><div class="no-row-height column-margin column-container"><span class="margin-aside"><img src="https://www.barbaratozier.com/assets/samo.png" class="img-fluid" width="20" alt="samoyed"></span></div></div>
<p>We are “separat[ing] the destination from the value”. I’m not quite sure what that means.</p>
<ol type="1">
<li>attach a value to the <code>NavigationLink</code>. It can be anything, but it must be <code>Hashable</code></li>
<li>attach a <code>navigationDestination()</code> modifier inside the navigation stack to let it know what to do</li>
</ol>
<ul>
<li>you can have multiple <code>navigationDestination()</code> calls depending on the type of data you are giving it</li>
<li>“most” of Swift’s data types conform to <code>Hashable</code></li>
<li>Hashing is a way to compare to complex objects easily. The hash value for each piece of data should be unique and consistent. In other words, you use hashing to make sure the large file you downloaded is what you thought you downloaded.</li>
<li>if you make a struct with properties that are all <code>Hashable</code> you can add the protocol to the struct to make it conform</li>
</ul>
<p>This is going to be a very confusing thing for me I think. Not that you need <code>Hashable</code> or that you wait until you need the view before you see it, but the <em>process</em> of navigating to a view. Can you style it? How? Nest a new <code>View</code> body?</p>


</section>
</section>

 ]]></description>
  <category>100 days</category>
  <category>SwiftUI</category>
  <guid>https://www.barbaratozier.com/posts/260601-100-days-of-swiftui-day-43/</guid>
  <pubDate>Mon, 01 Jun 2026 04:00:00 GMT</pubDate>
  <media:content url="https://www.barbaratozier.com/posts/260601-100-days-of-swiftui-day-43/Day43.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>100 Days of SwiftUI</title>
  <link>https://www.barbaratozier.com/posts/260531-100-days-of-swiftui-day-42/</link>
  <description><![CDATA[ 

<header id="title-block-header">

<p class="subtitle lead"><a href="https://www.hackingwithswift.com/100/swiftui/42">Day 42</a></p>

<p class="date">2026-05-31</p>
</header>


<section id="project-8-part-4" class="level2">
<h2 class="anchored" data-anchor-id="project-8-part-4">Project 8, part 4</h2>
<p>Moonshot wrap up and challenges</p>
<p><strong>Quiz:</strong> 11/12</p>
</section>
<section id="challenges" class="level2">
<h2 class="anchored" data-anchor-id="challenges">Challenges</h2>
<blockquote class="blockquote">
<ol type="1">
<li>Add the launch date to MissionView, below the mission badge. You might choose to format this differently given that more space is available, but it’s down to you.</li>
</ol>
</blockquote>
<p>I copied the code from <code>ContentView</code> and put it just below the badge with some reformatting</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode swift code-with-copy"><code class="sourceCode swift"><span id="cb1-1">Text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Launch date: </span><span class="er" style="color: #AD0000;
background-color: null;
font-style: inherit;">\(</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">mission.formattedLaunchDate)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb1-2">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>font<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(.</span>headline<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb1-3">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>foregroundStyle<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(.</span>textColorPrimary<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div></div>
<blockquote class="blockquote">
<ol start="2" type="1">
<li>Extract one or two pieces of view code into their own new SwiftUI views – the horizontal scroll view in MissionView is a great candidate, but if you followed my styling then you could also move the Rectangle dividers out too.</li>
</ol>
</blockquote>
<p>Hah! I already did the <code>Rectangle</code> dividers <a href="../260530-100-days-of-swiftui-day-41">yesterday</a>, so let’s do another one.</p>
<p>I think the <code>Image</code> calls are a good candidate. There are 4 of them, all with <code>.resizable()</code>. 3 of the 4 have <code>scaledToFit()</code>. I checked the one that doesn’t (crew member image) and putting it on didn’t seem to cause any issues.</p>
<p>So I replaced 2 lines written 4 times with a little extension and 1 line 4 times. Small in this, but a great way to harmonize an app.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode swift code-with-copy"><code class="sourceCode swift"><span id="cb2-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">extension</span> Image <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb2-2">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">func</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">imageResizableAndScaledToFit</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">()</span> -&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">some</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">View</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb2-3">        <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">self</span></span>
<span id="cb2-4">            <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>resizable<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">()</span></span>
<span id="cb2-5">            <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>scaledToFit<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">()</span></span>
<span id="cb2-6">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb2-7"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb2-8"></span>
<span id="cb2-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Usage:</span></span>
<span id="cb2-10"></span>
<span id="cb2-11">Image<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>astronaut<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>id<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb2-12">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>imageResizableAndScaledToFit<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">()</span></span></code></pre></div></div>
<blockquote class="blockquote">
<ol start="3" type="1">
<li>For a tough challenge, add a toolbar item to ContentView that toggles between showing missions as a grid and as a list.</li>
</ol>
</blockquote>
<p>Well the concept was pretty simple, make a toggle that would set <code>isViewGridEnabled</code> to <code>true</code> for “Grid” and <code>false</code> for “List”. Getting the styling right however…</p>
<p>First, I did</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode swift code-with-copy"><code class="sourceCode swift"><span id="cb3-1">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">@State</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">private</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">var</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">isViewGridEnabled</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Bool <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span></span>
<span id="cb3-2">    </span>
<span id="cb3-3">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">var</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">columns</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">[</span>GridItem<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">]</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{[</span></span>
<span id="cb3-4">        GridItem<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(.</span>adaptive<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>minimum<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> isViewGridEnabled <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">150</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>infinity<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">))</span></span>
<span id="cb3-5">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">]}</span></span></code></pre></div></div>
<p>Then after the <code>.navigationTitle</code> I added</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode swift code-with-copy"><code class="sourceCode swift"><span id="cb4-1"> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>toolbar <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb4-2">     ToolbarItem<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>placement<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>bottomBar<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb4-3">         Toggle<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>isOn<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> $isViewGridEnabled<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb4-4">             Text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>isViewGridEnabled <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Show As List"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Show As Grid"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb4-5">                 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>foregroundStyle<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(.</span>textColorSecondary<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb4-6">         <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-7">         <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>toggleStyle<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(.</span><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">switch</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb4-8">         <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>tint<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(.</span>darkBackground<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb4-9">     <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span></code></pre></div></div>
<p>The <code>.tint(.darkBackground)</code> is there to not have a BRIGHT GREEN toggle</p>
<p>Putting the toolbar in the <code>.bottomBar</code> throws a warning &gt;Adding ‘UIKitToolbar’ as a subview of UIHostingController.view is not supported and may result in a broken view hierarchy. Add your view above UIHostingController.view in a common superview or insert it into your SwiftUI content in a UIViewRepresentable instead.</p>
<p>I tried to fix it by adding <code>.compositingGroup()</code> to the <code>.toolbar</code> modifiers but it didn’t make a difference. Since I really prefer this to be on the bottom, I’m going to ignore the warning.</p>
<p>Here it is!</p>
<p><img src="https://www.barbaratozier.com/posts/260531-100-days-of-swiftui-day-42/gridview.png" class="postimg img-fluid" alt="screencap of grid view of opening page">&nbsp;<img src="https://www.barbaratozier.com/posts/260531-100-days-of-swiftui-day-42/listview.png" class="postimg img-fluid" alt="screencap of list view of opening page">&nbsp;<img src="https://www.barbaratozier.com/posts/260531-100-days-of-swiftui-day-42/moonshot.gif" class="img-fluid" alt="animated gif showing the operation of the app"><br>
</p>


</section>

 ]]></description>
  <category>100 days</category>
  <category>SwiftUI</category>
  <guid>https://www.barbaratozier.com/posts/260531-100-days-of-swiftui-day-42/</guid>
  <pubDate>Sun, 31 May 2026 04:00:00 GMT</pubDate>
  <media:content url="https://www.barbaratozier.com/posts/260531-100-days-of-swiftui-day-42/Day42.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>100 Days of SwiftUI</title>
  <link>https://www.barbaratozier.com/posts/260530-100-days-of-swiftui-day-41/</link>
  <description><![CDATA[ 

<header id="title-block-header">

<p class="subtitle lead"><a href="https://www.hackingwithswift.com/100/swiftui/41">Day 41</a></p>

<p class="date">2026-05-30</p>
</header>


<section id="project-8-part-3" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="project-8-part-3">Project 8, part 3</h2>
<p>Finishing the Moonshot app</p>
<section id="showing-mission-details-with-scrollview-and-containerrelativeframe" class="level3">
<h3 class="anchored" data-anchor-id="showing-mission-details-with-scrollview-and-containerrelativeframe">Showing mission details with <code>ScrollView</code> and <code>containerRelativeFrame()</code></h3>
<ul>
<li>nesting <code>VStack()</code>s to tweak alignments (image vs text)</li>
<li>adding parameters to the <code>#Preview</code> so you can see what you’re designing</li>
</ul>
</section>
<section id="merging-codable-structs" class="level3">
<h3 class="anchored" data-anchor-id="merging-codable-structs">Merging <code>Codable</code> structs</h3>
<ul>
<li>it’s kinda like a visible <code>JOIN</code></li>
<li>uses <code>.map</code> which is a thing I don’t entirely understand</li>
<li>admonition that your data better be clean and present!</li>
<li>you can’t put a shaped border on a <code>clipShape()</code> – you need to use an <code>overlay()</code></li>
</ul>
<p>I tried using a <code>background()</code> with the same shape, but couldn’t get the border to follow</p>
<p>OH, <code>border</code> and <code>strokeBorder</code> are <strong>not</strong> the same thing</p>
<p>I did manage to create my own <code>divideSection()</code> view so I can use it multiple places</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode swift code-with-copy"><code class="sourceCode swift"><span id="cb1-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">extension</span> View <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb1-2">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">func</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">divideSection</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">()</span> -&gt; <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">some</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">View</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span></span>
<span id="cb1-3">        Rectangle<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">()</span></span>
<span id="cb1-4">            <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>frame<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>height<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb1-5">            <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>foregroundStyle<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(.</span>lightBackground<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb1-6">            <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>padding<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(.</span>vertical<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb1-7">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb1-8"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span></code></pre></div></div>
<p>(<code>.lightBackground</code> is in another extension based on <code>ShapeStyle ... Color</code>)</p>
<p>I figure eventually I’ll have a few files of “helpers”…</p>
</section>
<section id="finishing-up-with-one-last-view" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="finishing-up-with-one-last-view">Finishing up with one last view</h3>
<div class="page-columns page-full"><p>We have the main screen and the missions screen, now for the astronauts!  It’s a simple view, where you pass in the <code>Astronaut</code> object and display the information within it.</p><div class="no-row-height column-margin column-container"><span class="margin-aside">At this point “astronaut” doesn’t look ever look correctly spelled.</span></div></div>
<p><span class="break">&nbsp;</span></p>
<p>Notice that we’ve done 3 days and haven’t finished the app just yet. They’re getting bigger!</p>


</section>
</section>

 ]]></description>
  <category>100 days</category>
  <category>SwiftUI</category>
  <guid>https://www.barbaratozier.com/posts/260530-100-days-of-swiftui-day-41/</guid>
  <pubDate>Sat, 30 May 2026 04:00:00 GMT</pubDate>
  <media:content url="https://www.barbaratozier.com/posts/260530-100-days-of-swiftui-day-41/Day41.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>100 Days of SwiftUI</title>
  <link>https://www.barbaratozier.com/posts/260529-100-days-of-swiftui-day-40/</link>
  <description><![CDATA[ 

<header id="title-block-header">

<p class="subtitle lead"><a href="https://www.hackingwithswift.com/100/swiftui/40">Day 40</a></p>

<p class="date">2026-05-29</p>
</header>


<section id="project-8-part-2" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="project-8-part-2">Project 8, part 2</h2>
<ul>
<li>Focus on getting the data right</li>
<li>Meeting <em>generics</em></li>
<li>getting more comfortable with splitting code out of the main <code>ContentView</code></li>
<li>colors!</li>
</ul>
<section id="loading-a-specific-kind-of-codable-data" class="level3">
<h3 class="anchored" data-anchor-id="loading-a-specific-kind-of-codable-data">Loading a specific kind of <code>Codable</code> data</h3>
<ul>
<li>bringing JSON data in; need to consider how to do it in a way that is easy to maintain and doesn’t “clutter our code”</li>
<li>moved <code>Decode</code> code out of <code>ContentView</code> into another file
<ol type="1">
<li>makes <code>ContentView</code> easier to read</li>
<li>gives the possibility to easily reuse the code in another project
<ul>
<li>aided by adding more reasons to throw <code>FatalError</code></li>
</ul></li>
</ol></li>
</ul>
</section>
<section id="using-generics-to-load-any-kind-of-codable-data" class="level3 page-columns page-full">
<h3 class="anchored" data-anchor-id="using-generics-to-load-any-kind-of-codable-data">Using generics to load any kind of <code>Codable</code> data</h3>
<ul>
<li>you can nest structs to give added context (so instead of talking about <code>Crew</code>, you talk about <code>Mission.Crew</code>)</li>
<li><em>generics</em> allow code to work with a variety of different types (such as a dictionary of astronauts and an array of missions)</li>
<li>uses a placeholder, conventionally <code>T</code> in angle brackets (aka “Pulp Fiction brackets”?!)  after the <code>func</code> name, <em>e.g.</em> <code>func decode&lt;T&gt;...</code> </li>
<li>note that <code>T</code> stands for the type of thing, so if it’s already an array, you don’t need to use <code>[T]</code></li>
<li>when you actually go to use the function you have to tell it what it is going to return <img src="https://www.barbaratozier.com/assets/samo.png" class="img-fluid" alt="tiny sketch of a samoyed face with lolling tongue"><br>
</li>
</ul>
<div class="no-row-height column-margin column-container"><span class="margin-aside"><img src="https://www.barbaratozier.com/posts/260529-100-days-of-swiftui-day-40/pulpfiction.jpeg" class="img-fluid" alt="John Travolta holding two fingers in a v-shape pointing at the side of his head">&nbsp;We call them “chicken beaks”</span><span class="margin-aside">Or maybe it should be <img src="https://www.barbaratozier.com/posts/260529-100-days-of-swiftui-day-40/batman-dance.gif" class="img-fluid" alt="Adam West as Batman doing the Watusi"></span></div></section>
<section id="formatting-our-mission-view" class="level3">
<h3 class="anchored" data-anchor-id="formatting-our-mission-view">Formatting our mission view</h3>
<ul>
<li>the images we’re using are named <code>apollo1, apollo7...</code> but the <code>id</code> in the <code>Mission</code> struct (and the JSON) is just an integer.</li>
<li>adding a “Display name” property to the <code>Mission</code> struct makes it possible to have only one place where you need to develop the name for views.</li>
<li>same for formatted dates (so they read correctly in different locales)</li>
<li>you can specify app colors with Assets or with an extension. One is better for visual, other is better for version control</li>
<li><code>Color</code> conforms to <code>ShapeStyle</code>, so extend <em>that</em>
<ul>
<li>I did it for the text color also</li>
</ul></li>
<li>you can set a preferred display mode (<code>.preferredColorScheme(.light)</code> or <code>.dark</code>) so you don’t have to design the colors twice ;)</li>
</ul>


</section>
</section>

 ]]></description>
  <category>100 days</category>
  <category>SwiftUI</category>
  <guid>https://www.barbaratozier.com/posts/260529-100-days-of-swiftui-day-40/</guid>
  <pubDate>Fri, 29 May 2026 04:00:00 GMT</pubDate>
  <media:content url="https://www.barbaratozier.com/posts/260529-100-days-of-swiftui-day-40/Day40.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>SwiftUI animation</title>
  <link>https://www.barbaratozier.com/posts/260528-swiftui-animation/</link>
  <description><![CDATA[ 

<header id="title-block-header">


<p class="date">2026-05-28</p>
</header>


<p>In addition to the <a href="../../posts.html#category=100 days">100 Days of SwiftUI</a> project, I’m playing around with a MacOS app.</p>
<p>I have 2 screens that I want to go between with a nice transition. I found a nice example <a href="https://stackoverflow.com/questions/61424225/macos-swiftui-navigation-for-a-single-view/63679567#63679567">on Stack Overflow</a> and I like how it looks.</p>
<p>However, XCode is complaining that “animation was deprecated” and I should use <code>withAnimation</code> or <code>animation(_:value:)</code> and I can<strong>not</strong> figure out how to make it go.</p>
<p>Here’s the offending portion:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode swift code-with-copy"><code class="sourceCode swift"><span id="cb1-1">rootView<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">()</span></span>
<span id="cb1-2">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>frame<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>maxWidth<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>infinity<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> maxHeight<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>infinity<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb1-3">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>transition<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>AnyTransition<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>move<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>edge<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>leading<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">))</span></span>
<span id="cb1-4">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>animation<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(.</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">default</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div></div>
<p>I have at least two problems.</p>
<ol type="1">
<li>What animation <code>value</code>? I know it has to be linked to a <code>State</code> variable, but my <code>View</code> struct is in a separate file</li>
<li>If I use <code>withAnimation</code> where does it go? I tried putting it on the button that calls the second screen but that didn’t seem to make any difference (once I got it to compile, that is)</li>
</ol>
<p>Here’s what I want it to look like:</p>
<p><video src="sliding.mov" class="img-fluid" controls=""><a href="sliding.mov">a movie showing screens moving smoothly in to view</a></video><br>
</p>
<p>What I get (no video this time), is just a quick change of screen without any nice transitions.</p>
<p>Maybe I should turn this into some sort of animation settings project…</p>



 ]]></description>
  <category>SwiftUI</category>
  <guid>https://www.barbaratozier.com/posts/260528-swiftui-animation/</guid>
  <pubDate>Thu, 28 May 2026 04:00:00 GMT</pubDate>
  <media:content url="https://www.barbaratozier.com/assets/phs/ph10.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>100 Days of SwiftUI</title>
  <link>https://www.barbaratozier.com/posts/260528-100-days-of-swiftui-day-39/</link>
  <description><![CDATA[ 

<header id="title-block-header">

<p class="subtitle lead"><a href="https://www.hackingwithswift.com/100/swiftui/39">Day 39</a></p>

<p class="date">2026-05-28</p>
</header>


<section id="project-8-part-1" class="level2">
<h2 class="anchored" data-anchor-id="project-8-part-1">Project 8, part 1</h2>
<p>Moonshot — let users learn about the NASA Apollo program</p>
<section id="resizing-images-to-fit-the-available-space" class="level3">
<h3 class="anchored" data-anchor-id="resizing-images-to-fit-the-available-space">Resizing images to fit the available space</h3>
<p>As anyone who has dealt with trying to make images fit proportionally to an area (HTML I’m looking at you), it’s never as easy as saying “here’s an image, here’s a space, make it happen.”</p>
<p>And SwiftUI does it with a <em>boatload</em> of modifiers</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode swift code-with-copy"><code class="sourceCode swift"><span id="cb1-1">Image<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(.</span>example<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb1-2">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>resizable<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">().</span>    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// can be resized</span></span>
<span id="cb1-3">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>scaledToFit<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">().</span>  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// don't squish the image</span></span>
<span id="cb1-4">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>containerRelativeFrame<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(.</span>horizontal<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{</span> size<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> axis <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span></span>
<span id="cb1-5">        size <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.8</span>   <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// use 80% of the available width</span></span>
<span id="cb1-6">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span></code></pre></div></div>
<p>I’ve been wondering about relative width!</p>
</section>
<section id="how-scrollview-lets-us-work-with-scrolling-data" class="level3">
<h3 class="anchored" data-anchor-id="how-scrollview-lets-us-work-with-scrolling-data">How <code>ScrollView</code> lets us work with scrolling data</h3>
<ul>
<li>use <code>ScrollView { … }</code> instead of say, <code>List</code></li>
<li>when views are added to a scroll view they are immediately created (whether you can see them or not)</li>
<li>consider using <code>LazyVStack</code> (or the H equivalent)</li>
<li>lazy stacks take up all available space, as opposed to regular stacks that take up only what they need</li>
</ul>
</section>
<section id="pushing-new-views-onto-the-stack-using-navigationlink" class="level3">
<h3 class="anchored" data-anchor-id="pushing-new-views-onto-the-stack-using-navigationlink">Pushing new views onto the stack using <code>NavigationLink</code></h3>
<ul>
<li>View stacks a fundamental way of working with iOS</li>
<li>different from sheets because of how the information is presented</li>
<li>a NavStack with <code>NavigationLink</code> destination (which can be any view)</li>
<li>use for details about the current selection</li>
<li>sheet is for unrelated content</li>
</ul>
</section>
<section id="working-with-hierarchical-codable-data" class="level3">
<h3 class="anchored" data-anchor-id="working-with-hierarchical-codable-data">Working with hierarchical <code>Codable</code> data</h3>
<ul>
<li>for example, an array inside another array, with different data types</li>
<li>used in conjunction with JSON, will go as far down as the data does (as long as it’s valid JSON of course)</li>
</ul>
</section>
<section id="how-to-lay-out-views-in-a-scrolling-grid" class="level3">
<h3 class="anchored" data-anchor-id="how-to-lay-out-views-in-a-scrolling-grid">How to lay out views in a scrolling grid</h3>
<ul>
<li>good for showing columns of information</li>
<li><code>LazyVGrid</code> to show vertical data; <code>LazyHGrid</code> for horizontal</li>
<li>can use adaptive modifier to use up available space rather than specifying the exact number of columns, <em>e.g.</em> <code>let layout = [ GridItem(.adaptive(minimum: 80, maximum: 120)), ]</code></li>
</ul>


</section>
</section>

 ]]></description>
  <category>100 days</category>
  <category>SwiftUI</category>
  <guid>https://www.barbaratozier.com/posts/260528-100-days-of-swiftui-day-39/</guid>
  <pubDate>Thu, 28 May 2026 04:00:00 GMT</pubDate>
  <media:content url="https://www.barbaratozier.com/posts/260528-100-days-of-swiftui-day-39/Day39.jpg" medium="image" type="image/jpeg"/>
</item>
<item>
  <title>100 Days of SwiftUI</title>
  <link>https://www.barbaratozier.com/posts/260527-100-days-of-swiftui-day-38/</link>
  <description><![CDATA[ 

<header id="title-block-header">

<p class="subtitle lead"><a href="https://www.hackingwithswift.com/100/swiftui/38">Day 38</a></p>

<p class="date">2026-05-27</p>
</header>


<section id="project-7-part-3" class="level2">
<h2 class="anchored" data-anchor-id="project-7-part-3">Project 7, part 3</h2>
<p>iExpense wrap up and challenges</p>
<p><strong>Quiz:</strong> 12/12</p>
</section>
<section id="challenge" class="level2 page-columns page-full">
<h2 class="anchored" data-anchor-id="challenge">Challenge</h2>
<blockquote class="blockquote">
<ol type="1">
<li>Use the user’s preferred currency, rather than always using US dollars.</li>
</ol>
</blockquote>
<p>This one required revisiting the WeSplit app <code>.currency(code: Locale.current.currency?.identifier ?? "USD")</code></p>
<p>Remember to replace it in two places!</p>
<p>I wasn’t able to check this, though, because I couldn’t figure out how to change the region for the simulated phone. I could set it to, say, Germany <code>.environment(\.locale, Locale(identifier: "de_DE"))</code> but it would just change the decimal point to a comma and move the <code>$</code> to the end. I expected <code>€</code></p>
<blockquote class="blockquote">
<ol start="2" type="1">
<li>Modify the expense amounts in ContentView to contain some styling depending on their value – expenses under $10 should have one style, expenses under $100 another, and expenses over $100 a third style. What those styles are depend on you.</li>
</ol>
</blockquote>
<p>I solved this using a nested ternary. Maybe not the cleanest? but it was better than separate <code>Text()</code> views IMO.</p>
<p>Here is the code from the first two challenges together (not including the currency line in <code>AddView</code>)</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode swift code-with-copy"><code class="sourceCode swift"><span id="cb1-1">Text<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span id="cb1-2">    item<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>amount<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-3">    format<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>currency<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span id="cb1-4">        code<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Locale<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>current<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>currency<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span>identifier</span>
<span id="cb1-5">            <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">??</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"USD"</span></span>
<span id="cb1-6">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb1-7"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb1-8"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>foregroundStyle<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span id="cb1-9">    item<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>amount <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">100.0</span></span>
<span id="cb1-10">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>red</span>
<span id="cb1-11">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>item<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>amount <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">10.0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>secondary <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>primary<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb1-12"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div></div>
<blockquote class="blockquote">
<ol start="3" type="1">
<li>For a bigger challenge, try splitting the expenses list into two sections: one for personal expenses, and one for business expenses. This is tricky for a few reasons, not least because it means being careful about how items are deleted!</li>
</ol>
</blockquote>
<div class="page-columns page-full"><p>So yesterday I did add the date to the expense record.  Then I made a little ternary operator to color the row depending on it’s type (business or personal). Here’s what that looks like (it’s attached to the <code>HStack</code>)</p><div class="no-row-height column-margin column-container"><span class="margin-aside">It really is necessary to know when you made an expense.</span></div></div>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode swift code-with-copy"><code class="sourceCode swift"><span id="cb2-1"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>listRowBackground<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span></span>
<span id="cb2-2">    item<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>type <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Business"</span></span>
<span id="cb2-3">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> Color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>red<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> green<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> blue<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> opacity<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb2-4">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>red<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> green<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.75</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> blue<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> opacity<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb2-5"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div></div>
<p>Then in my <code>ForEach</code> I sorted by date ascending <code>expenses.items.sorted(by: {$0.date &lt; $1.date})</code></p>
<p>This means I can see at a glance which expense items are personal and which are business. Not the challenge he suggested though, so let’s see if I can manage it.</p>
<p>Well one way is to sort the list on multiple values</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode swift code-with-copy"><code class="sourceCode swift"><span id="cb3-1">ForEach<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>expenses<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>items<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span>sorted<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>by<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">{(</span>$<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.</span>type<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> $<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.</span>date<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(</span>$<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.</span>type<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> $<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.</span>date<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">)}))</span> </span></code></pre></div></div>
<p>This sorts by type first (Business or personal), then date <em>descending</em>. I tried putting amount in the sort, but I think the date object includes time so… 🤷‍♀️</p>
<p><span class="break">&nbsp;</span></p>
<p>OK, I did it, but there’s a bit of duplication that I don’t like. Basically I filter the list twice, and show each list in its own section. I should create an “expense details” view someday, but today is not that day.</p>
<p><img src="https://www.barbaratozier.com/posts/260527-100-days-of-swiftui-day-38/iexpense.gif" class="img-fluid" alt="gif showing functionality of the app"><br>
</p>


</section>

 ]]></description>
  <category>100 days</category>
  <category>SwiftUI</category>
  <guid>https://www.barbaratozier.com/posts/260527-100-days-of-swiftui-day-38/</guid>
  <pubDate>Wed, 27 May 2026 04:00:00 GMT</pubDate>
  <media:content url="https://www.barbaratozier.com/posts/260527-100-days-of-swiftui-day-38/Day38.jpg" medium="image" type="image/jpeg"/>
</item>
</channel>
</rss>
