<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Swiftui on Feel the magic of kool.</title><link>https://vladde.net/tags/swiftui/</link><description>Recent content in Swiftui on Feel the magic of kool.</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Mon, 12 Oct 2026 01:15:58 +0200</lastBuildDate><atom:link href="https://vladde.net/tags/swiftui/index.xml" rel="self" type="application/rss+xml"/><item><title>SwiftUI iOS list styles (with images)</title><link>https://vladde.net/blog/swiftui-ios-list-styles/</link><pubDate>Mon, 02 Oct 2023 09:17:48 +0200</pubDate><guid>https://vladde.net/blog/swiftui-ios-list-styles/</guid><description>&lt;h2 data-rfc-heading=plain id=introduction>Introduction&lt;/h2>
&lt;p>SwiftUI provides multiple styles for list, but it might not always be obvious what difference there are between them.&lt;/p>
&lt;p>This is a comparison grid of all iOS list styles, described in [&lt;a href="https://developer.apple.com/documentation/swiftui/liststyle">STYLES&lt;/a>]. The code for the list is written out at the bottom of the page.&lt;/p>
&lt;h2 id="comparisons">Comparisons&lt;/h2>
&lt;div style='display: grid; grid-template-columns: 1fr 1fr; align-items: start;'>
 &lt;figure>
 &lt;figcaption>.plain&lt;/figcaption>
 &lt;img alt='plain style list' width=1170 height=876 src=plain.png>
 &lt;/figure>
 &lt;figure>
 &lt;figcaption>.inset&lt;/figcaption>
 &lt;img alt='inset style list' width=1170 height=876 src=inset.png>
 &lt;/figure>
 &lt;figure>
 &lt;figcaption>.grouped&lt;/figcaption>
 &lt;img alt='grouped style list' width=1170 height=876 src=grouped.png>
 &lt;/figure>
 &lt;figure>
 &lt;figcaption>.insetGrouped&lt;/figcaption>
 &lt;img alt='insetGrouped style list' width=1170 height=876 src=insetGrouped.png>
 &lt;/figure>
 &lt;figure>
 &lt;figcaption>.sidebar&lt;/figcaption>
 &lt;img alt='sidebar style list' width=1170 height=876 src=sidebar.png>
 &lt;/figure>
&lt;/div>
&lt;h3 id="code">Code&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#e5e5e5;background-color:#000;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-swift" data-lang="swift">&lt;span style="display:flex;">&lt;span>List {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Section {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Text(&lt;span style="color:#0ff;font-weight:bold">&amp;#34;Apple&amp;#34;&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Text(&lt;span style="color:#0ff;font-weight:bold">&amp;#34;Banana&amp;#34;&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> } header: {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Text(&lt;span style="color:#0ff;font-weight:bold">&amp;#34;Favorites&amp;#34;&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> } footer: {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Text(&lt;span style="color:#0ff;font-weight:bold">&amp;#34;The fruits which are most tasty&amp;#34;&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Section {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Text(&lt;span style="color:#0ff;font-weight:bold">&amp;#34;Orange&amp;#34;&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="references">References&lt;/h2>
&lt;dl>
 &lt;dt>[STYLES]&lt;/dt>
 &lt;dd>Apple Inc., &lt;a href="https://developer.apple.com/documentation/swiftui/liststyle">ListStyle&lt;/a>, Apple Developer Documentation&lt;/dd>
&lt;/dl></description></item><item><title>SwiftUI iOS List default selection with NavigationSplitView</title><link>https://vladde.net/blog/swiftui-splitview-default/</link><pubDate>Thu, 17 Aug 2023 02:48:52 +0200</pubDate><guid>https://vladde.net/blog/swiftui-splitview-default/</guid><description>&lt;h2 data-rfc-heading=plain id=introduction>Introduction&lt;/h2>
&lt;p>Looking through Apple&amp;rsquo;s documentation, I found no clear example of how to set a default selected option for a List in a NavigationSplitView.&lt;/p>
&lt;p>This post shows how to the the default selected option in a list, and how to best interact with a split view.&lt;/p>
&lt;h2 id="example">Example&lt;/h2>
&lt;p>Clear example of how to set a default selected option for a sidebar List in a NavigationSplitView.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#e5e5e5;background-color:#000;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-swift" data-lang="swift">&lt;span style="display:flex;">&lt;span>@State &lt;span style="color:#fff;font-weight:bold">private&lt;/span> &lt;span style="color:#fff;font-weight:bold">var&lt;/span> selectedId: &lt;span style="color:#fff;font-weight:bold">String&lt;/span>? = &lt;span style="color:#0ff;font-weight:bold">&amp;#34;banana&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>NavigationSplitView {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> List(selection: &lt;span style="color:#f00">$&lt;/span>selectedId) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> NavigationLink(value: &lt;span style="color:#0ff;font-weight:bold">&amp;#34;apple&amp;#34;&lt;/span>) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Text(&lt;span style="color:#0ff;font-weight:bold">&amp;#34;Apple&amp;#34;&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> NavigationLink(value: &lt;span style="color:#0ff;font-weight:bold">&amp;#34;banana&amp;#34;&lt;/span>) {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Text(&lt;span style="color:#0ff;font-weight:bold">&amp;#34;Banana&amp;#34;&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>} detail: {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Text(&lt;span style="color:#0ff;font-weight:bold">&amp;#34;&lt;/span>&lt;span style="color:#0ff;font-weight:bold">\(&lt;/span>selectedId ?? &lt;span style="color:#0ff;font-weight:bold">&amp;#34;Nothing selected&amp;#34;&lt;/span>&lt;span style="color:#0ff;font-weight:bold">)&lt;/span>&lt;span style="color:#0ff;font-weight:bold">&amp;#34;&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>We use &amp;quot;&lt;code>NavigationLink&lt;/code>&amp;quot; with a &amp;quot;&lt;code>value:&lt;/code>&amp;quot; parameter instead of navigating to a new view, and keep track of the selection in &amp;quot;&lt;code>selectedId&lt;/code>&amp;quot;; the &amp;ldquo;selected&amp;rdquo; value must be optional for iOS [1].&lt;/p></description></item></channel></rss>