<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Posts on Ahmed Komsan</title><link>https://ahmedkomsan.com/posts/</link><description>Recent content in Posts on Ahmed Komsan</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Mon, 19 Oct 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://ahmedkomsan.com/posts/index.xml" rel="self" type="application/rss+xml"/><item><title>Swift - Powerful Yet Overlooked Functions for problem solving -- Part 1</title><link>https://ahmedkomsan.com/posts/2025-3-30-hidden-gems-in-swift-problem-solving-part1/</link><pubDate>Sun, 30 Mar 2025 00:00:00 +0000</pubDate><guid>https://ahmedkomsan.com/posts/2025-3-30-hidden-gems-in-swift-problem-solving-part1/</guid><description>&lt;p&gt;Swift is known for its simplicity and expressive syntax, but some incredibly powerful functions often go unnoticed. These lesser-known built-in functions can help solve common programming challenges more efficiently, making your code more readable, concise, and performant.&lt;/p&gt;&#10;&lt;p&gt;let&amp;rsquo;s explore a set of Swift functions that will help you write cleaner, more elegant solutions to everyday problems.&lt;/p&gt;&#10;&lt;h3 id="what-well-cover"&gt;What we&amp;rsquo;ll cover&lt;/h3&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Smarter iteration and loops with &lt;code&gt;stride&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;combining sequence and parallel Iteration with &lt;code&gt;zip &lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;Quick validation with &lt;code&gt;allSatisfy(_:)&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;Lazy Sequence Generation with &lt;code&gt;sequence&lt;/code&gt;&lt;/li&gt;&#10;&lt;li&gt;Categorizing data with &lt;code&gt;Dictionary(grouping:by:)&lt;/code&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h3 id="smarter-iteration-and-loops-with-stride"&gt;Smarter iteration and loops with &lt;code&gt;stride&lt;/code&gt;&lt;/h3&gt;&#10;&lt;p&gt;Stride function provides a flexible way to create sequences of values based on a specific range and step, making it useful for various looping and iteration scenarios in Swift.&lt;/p&gt;</description></item><item><title>KeyPaths in swift</title><link>https://ahmedkomsan.com/posts/2021-6-22-keypaths-in-swift/</link><pubDate>Tue, 22 Jun 2021 00:00:00 +0000</pubDate><guid>https://ahmedkomsan.com/posts/2021-6-22-keypaths-in-swift/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="#1---what-are-keypaths-in-swift"&gt;1 - What are Keypaths in swift&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="#2---types-of-keypaths"&gt;2 - Types of KeyPaths&lt;/a&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;a href="#21-referencewritablekeypathroot-value"&gt;2.1 ReferenceWritableKeyPath&amp;lt;Root, Value&amp;gt;&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="#22-writablekeypathroot-value"&gt;2.2 WritableKeyPath&amp;lt;Root, Value&amp;gt;&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="#23-keypathroot-value"&gt;2.3 KeyPath&amp;lt;Root, Value&amp;gt;&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="#24-partialkeypath"&gt;2.4 PartialKeyPath&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="#25-anykeypath"&gt;2.5 AnyKeyPath&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="#3---swift-52-key-path-as-functions"&gt;3 - Swift 5.2: Key path as functions&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="#4---using-keypaths"&gt;4 - Using keyPaths&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="#see-also"&gt;See Also&lt;/a&gt;&lt;/li&gt;&#10;&lt;li&gt;&lt;a href="#conclusion"&gt;Conclusion&lt;/a&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="1---what-are-keypaths-in-swift"&gt;1 - What are Keypaths in swift&lt;/h2&gt;&#10;&lt;p&gt;KeyPath is an object that stores a reference to a property of a type, that keyPath object allow us later on to get/set their underlying value ( defer/stash getter and setter evaluation when needed ) using subscript operator. you can then pass these keypaths objects around to create an API with shorter and cleaner syntax.&lt;/p&gt;</description></item><item><title>Getting Started with Diffable Data Source</title><link>https://ahmedkomsan.com/posts/2020-7-17-getting-started-with-diffable-data-source/</link><pubDate>Fri, 17 Jul 2020 00:00:00 +0000</pubDate><guid>https://ahmedkomsan.com/posts/2020-7-17-getting-started-with-diffable-data-source/</guid><description>&lt;p&gt;Diffable Data Source is a new declarative API for &lt;code&gt;UITableView&lt;/code&gt; and its counterpart &lt;code&gt;UICollectionView&lt;/code&gt; introduced at WWDC19, IOS 13 as a replacement for &lt;code&gt;UITableViewDataSource&lt;/code&gt; and &lt;code&gt;UICollectionViewDataSource&lt;/code&gt;.&lt;/p&gt;&#10;&lt;p&gt;In this article we will take a brief look at &lt;code&gt;UITableViewDataSource&lt;/code&gt; then we will go directly to the new API and see how it works with an example.&lt;/p&gt;&#10;&lt;h3 id="uitableviewdatasource"&gt;UITableViewDataSource&lt;/h3&gt;&#10;&lt;p&gt;Previously, when working with &lt;code&gt;UITableView&lt;/code&gt; or &lt;code&gt;UICollectionView&lt;/code&gt; you would implement &lt;code&gt;UITableViewDataSource&lt;/code&gt; protocol providing the table view with the details of how to display cells and supplementary views ( headers and footers ) and what data you want to render.&lt;/p&gt;</description></item><item><title>Introduction to Function Builders in Swift</title><link>https://ahmedkomsan.com/posts/2020-7-11-introduction-to-function-builders-in-swift/</link><pubDate>Sat, 11 Jul 2020 00:00:00 +0000</pubDate><guid>https://ahmedkomsan.com/posts/2020-7-11-introduction-to-function-builders-in-swift/</guid><description>&lt;p&gt;Function builders is a swift language feature, first introduced in swift 5.1 available from Xcode 11. it helps in building declarative DSL ( Domain Specific Language ) for constructing user interface hierarchies or create an API that apply transformations to the statements in a way that make the API easier to read, understand and write.&lt;/p&gt;&#10;&lt;h2 id="what-are-function-builders"&gt;what are function builders&lt;/h2&gt;&#10;&lt;p&gt;function builders is nothing more than a type with certain functions that lets you easily build complex objects like HTML,XML or UIView hierarchies in a concise and readable way without any verbosity or in general apply some transformations to the statements of a function and combining them into a single result ( return value ). for example, this is how we create a HStack in SwiftUI.&lt;/p&gt;</description></item><item><title>From ASCII to Emoji: The Story of String Encoding in Swift</title><link>https://ahmedkomsan.com/posts/2026-10-19-string-encoding-in-swift/</link><pubDate>Mon, 19 Oct 2026 00:00:00 +0000</pubDate><guid>https://ahmedkomsan.com/posts/2026-10-19-string-encoding-in-swift/</guid><description>&lt;p&gt;Every &lt;code&gt;String&lt;/code&gt; you type in Xcode has a long, messy and surprisingly human story behind it. By the end of this article you will know why &lt;code&gt;&amp;quot;😀&amp;quot;.count&lt;/code&gt; is 1, but &lt;code&gt;&amp;quot;😀&amp;quot;.utf8.count&lt;/code&gt; is 4, and how we got there: from a 7-bit table in 1963 to emoji today.&lt;/p&gt;&#10;&lt;p&gt;Let&amp;rsquo;s follow that story and see how each step shows up in the Swift code you write today.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;1963 ● ASCII 7 bits, 128 English characters&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; │&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;1980s ● Code pages same byte, different characters&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; │&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;1991 ● Unicode one number for every character&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; │&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;1991–96 ● UTF-16 2 bytes (or 4), endianness problem&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; │&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;1992 ● UTF-8 variable length 1 to 4 bytes&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; │&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;2001 ● UTF-32 fixed 4 bytes&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; │&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;2010 ● Emoji one character, many character numbers&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; │&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;2014–19 ● Swift stored as UTF-8, shown as characters&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="the-basics"&gt;The Basics&lt;/h2&gt;&#10;&lt;p&gt;Before the story starts, we need four simple ideas. Everything later builds on them.&lt;/p&gt;</description></item></channel></rss>