<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Armaan Khan</title>
    <description>The latest articles on DEV Community by Armaan Khan (@armaan535kh).</description>
    <link>https://dev.to/armaan535kh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4139317%2Fd15819f1-d673-4a36-9416-630adf989899.png</url>
      <title>DEV Community: Armaan Khan</title>
      <link>https://dev.to/armaan535kh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/armaan535kh"/>
    <language>en</language>
    <item>
      <title>Structured Concurrency</title>
      <dc:creator>Armaan Khan</dc:creator>
      <pubDate>Mon, 05 Oct 2026 12:32:16 +0000</pubDate>
      <link>https://dev.to/armaan535kh/structured-concurrency-5f74</link>
      <guid>https://dev.to/armaan535kh/structured-concurrency-5f74</guid>
      <description>&lt;h2&gt;
  
  
  Lesson - 8 Structured Concurrency(Swift Concurrency)
&lt;/h2&gt;

&lt;p&gt;So far we have created independent tasks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Task {
    // task
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;what if we wants task to be have child-parent relationship?&lt;br&gt;
That's where structured concurrency comes in. Here parents manages the children's.&lt;/p&gt;

&lt;p&gt;This give us important guarantees around:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Life Time&lt;/li&gt;
&lt;li&gt;Cancellation&lt;/li&gt;
&lt;li&gt;Errors&lt;/li&gt;
&lt;li&gt;Completion&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  We will start with simple concurrency tool &lt;strong&gt;async let&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;suppose we have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;fetchUser&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"Armaan"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;fetchPosts&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"Post 1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Post 2"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we can do it them sequentially&lt;/p&gt;

&lt;p&gt;fetchUser&lt;br&gt;
████████&lt;br&gt;
        ↓&lt;br&gt;
       done&lt;br&gt;
        ↓&lt;br&gt;
fetchPosts&lt;br&gt;
████████&lt;br&gt;
        ↓&lt;br&gt;
       done&lt;/p&gt;

&lt;p&gt;If each task takes 2 seconds then roughly it would take 4 seconds.&lt;br&gt;
But these operations do not depend on each other.&lt;/p&gt;

&lt;p&gt;We can run them concurrently.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;fetchUser&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;fetchPosts&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;


&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;await&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now,&lt;/p&gt;

&lt;p&gt;fetchUser&lt;br&gt;
████████&lt;br&gt;
    ↓&lt;br&gt;
    └──────── done&lt;/p&gt;

&lt;p&gt;fetchPosts&lt;br&gt;
████████&lt;br&gt;
    ↓&lt;br&gt;
    └──────── done&lt;/p&gt;

&lt;p&gt;They can make progress concurrently. If each takes roughly 2 seconds it would take approximately  2 seconds rather than 4 seconds.&lt;/p&gt;

</description>
      <category>swift</category>
      <category>ios</category>
    </item>
    <item>
      <title>How to Group and Display a List by Date in SwiftUI</title>
      <dc:creator>Armaan Khan</dc:creator>
      <pubDate>Wed, 23 Sep 2026 11:21:57 +0000</pubDate>
      <link>https://dev.to/armaan535kh/how-to-group-and-display-a-list-by-date-in-swiftui-4ggh</link>
      <guid>https://dev.to/armaan535kh/how-to-group-and-display-a-list-by-date-in-swiftui-4ggh</guid>
      <description>&lt;h2&gt;
  
  
  Problem I Faced
&lt;/h2&gt;

&lt;p&gt;I was working a gym Mac app for myself, I am new to SwiftUI and Apple ecosystem. I think I might be an almost year learning swift.&lt;/p&gt;

&lt;p&gt;Till now I was just simply working on simple projects. Now I decided atleast I have to solve me daily problem.&lt;/p&gt;

&lt;p&gt;I need to create an app for gym where I can track my progress. &lt;/p&gt;

&lt;p&gt;While creating I got a Issue I want to fetch the workouts and show in the form of the list, but the problem was that I want to show the workouts that I have done according to the Dates.&lt;/p&gt;

&lt;h2&gt;
  
  
  How did I solved
&lt;/h2&gt;

&lt;p&gt;I used Swift Data to store my data locally. It generally stores the data in the flat list. To show my all workout according to date I have to convert flat list into dictioinay.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Converting flat list into Dictionary
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyy3alxcffwqt8bu1s65c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyy3alxcffwqt8bu1s65c.png" alt=" " width="800" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I created a Computed Property to convert the flat list into dictionary.&lt;/p&gt;

&lt;p&gt;Dictionary(grouping: workouts) { ... } is a built-in Swift tool that walks through every item in workouts, one at a time, and asks the closure: "what key should this item live under?"&lt;/p&gt;

&lt;p&gt;{ workout in Calendar.current.startOfDay(for: workout.date) }&lt;/p&gt;

&lt;p&gt;It takes workout.date (which might be Sept 23, 9:03 AM) and strips the time off, giving just Sept 23, 12:00 AM. This is important — without this step, the 9am workout and the 6pm workout would be treated as different keys (since their exact timestamps differ), and they'd never end up grouped together.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Two ForEachs
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6we2db2g8c12txavyrva.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6we2db2g8c12txavyrva.png" alt=" " width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, First ForEach shorts the items in the dictionary recent as first element.&lt;/p&gt;

&lt;p&gt;Dictionaries have no built-in order in Swift, so if you looped over .keys directly, the dates could appear in any random order, and it might change every time. That's why .sorted(by: &amp;gt;) is there — it sorts the dates newest-first (&amp;gt; means descending).&lt;/p&gt;

&lt;p&gt;groupedWorkouts[date] looks up the array of workouts belonging to that day.&lt;/p&gt;

</description>
      <category>swift</category>
      <category>ios</category>
    </item>
  </channel>
</rss>
