<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mhmd Ebrahim on Medium]]></title>
        <description><![CDATA[Stories by Mhmd Ebrahim on Medium]]></description>
        <link>https://medium.com/@mmd57917?source=rss-1e2f33afc330------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tPzxU7S4wrxkVuC0bT2XNw.png</url>
            <title>Stories by Mhmd Ebrahim on Medium</title>
            <link>https://medium.com/@mmd57917?source=rss-1e2f33afc330------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 11:06:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mmd57917/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Art of Reusability: Evolve]]></title>
            <link>https://medium.com/@mmd57917/the-art-of-reusability-evolve-b484f4156553?source=rss-1e2f33afc330------2</link>
            <guid isPermaLink="false">https://medium.com/p/b484f4156553</guid>
            <dc:creator><![CDATA[Mhmd Ebrahim]]></dc:creator>
            <pubDate>Tue, 08 Sep 2026 07:50:43 GMT</pubDate>
            <atom:updated>2026-09-08T07:50:43.438Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Story of Growing</h3><p>Two years ago, my mentor gave me a list of topics and asked me to pick one.</p><p>At that time, I had almost zero experience with any of them. Out of all the topics, I chose <strong>Design System.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*FReqoz9BhrXVxqrW5dWm7w.jpeg" /></figure><p>The funny part? I didn’t even know what a Design System was.</p><p>Actually, I didn’t even know the difference between <strong>Design System </strong>and <strong>System Design</strong>.</p><p>So I started doing what I always do when I find something new: researching.</p><p>I watched videos, read articles, experimented, and even read a small book about it. Eventually, <a href="https://medium.com/@mmd57917/the-art-of-reusability-8df6cb8db3be?sharedUserId=mmd57917">I published an article filled with theoretical information about Design System</a>.</p><p>A few months later, I joined 4Sale.</p><p>During one of the standups, I heard someone mention a PoC for automating design tokens and the design system.</p><p>Wait… <strong>Design System? I know this topic!</strong></p><p>I immediately sent him a message asking if I could help. He explained the idea to me, and honestly, it was really interesting.</p><p>And once again, I did the same thing.</p><p>I started researching.</p><p>I watched videos, read articles, experimented, and learned a lot about automating Design Systems. We ended up using <a href="https://styledictionary.com/"><strong>Style Dictionary</strong></a>, and that experience helped me understand how design tokens could actually move from theory into a real product.</p><p>A few months ago, I landed my first full-time job at a cool startup in the travel industry.</p><p>We’re launching this month, and I honestly can’t wait.</p><p>Back when I wrote my Design System article, I stopped around <a href="https://medium.com/@mmd57917/the-art-of-reusability-8df6cb8db3be/share/mmd57917?source=social.linkedin&amp;_nonce=LMUmKnwo">Step 9: Create Reusable Components.</a></p><p>I had learned how to turn typography, fonts, and colors into tokens and enums. Then we moved on to building reusable components, using something simple like a button as an example.</p><p>But UI isn’t just buttons.</p><p>Then my lead introduced something new:</p><p><strong>Atomic Design.</strong></p><p>And once again, I had that same feeling.</p><p><em>Wow, another thing I don’t fully understand yet.</em></p><p>So I started reading about it and learning how to divide and organize components in a more scalable way.</p><p>And that’s when I realized something.</p><p>Compared to the first time I heard about Design System, I’ve learned a lot.</p><p>And I’m still learning.</p><p>I’m currently discovering <strong>System Design</strong> too — reading <a href="https://www.amazon.com/Mobile-System-Design-Interview-Insiders/dp/1736049151">Mobile System Design Interview</a> and watching mock interviews from <a href="https://www.youtube.com/@andrey_tech">this channel</a>.</p><p>It’s funny looking back.</p><p>Two years ago, I didn’t even know the difference between Design System and System Design.</p><p>Today, I’m still discovering both.</p><p>That’s the point.</p><p><strong>That’s how we grow.</strong></p><p>You don’t need to know everything.</p><p>You just need to stay curious enough to learn the next thing.</p><p>Don’t stop reading articles and books. Watch tutorials. Experiment. Build things. Break things.</p><p>And don’t abuse AI to the point where you stop thinking and learning.</p><p>I’m not anti-AI — I literally used it to fix and arrange what you’re reading right now.</p><p><strong>Use the tools. But don’t let the tools use you.</strong></p><p>This part is intentionally very short on the technical side. I didn’t explain Design Systems, Design Tokens, or Atomic Design.</p><p>I’ll leave that part to you.</p><p>Go research them.</p><p><strong>Keep evolving.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b484f4156553" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apple Tree: The SwiftUI Way 2]]></title>
            <link>https://medium.com/@mmd57917/apple-tree-the-swiftui-way-2-3d35ef1d6728?source=rss-1e2f33afc330------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d35ef1d6728</guid>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Mhmd Ebrahim]]></dc:creator>
            <pubDate>Tue, 20 May 2025 10:43:33 GMT</pubDate>
            <atom:updated>2025-05-20T10:43:33.083Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*-b11wj6JkXMSvOTjMnmgpg.gif" /></figure><h3>Back to the Roots 🎯</h3><p>It’s been a while, but good things take time, right?</p><p>About five months ago, we kicked off our Apple Tree journey by exploring SwiftUI’s view tree — the backbone of every UI we build. Since then, I’ve been diving deeper into SwiftUI through hands-on projects and constant learning.</p><p>I used SwiftUI in my game for the <strong>Swift Student Challenge</strong>, made a few small contributions, read more articles, and watched plenty of <strong>WWDC</strong> sessions. Lately, I’ve also been building a custom <strong>SwiftUI TextField kit</strong> — a fun dive into customization that taught me a lot. I’m super excited to release it soon as a Swift package!</p><p>In this part, we’ll uncover the secret ingredients that power SwiftUI: value types, identity, lifecycle, and the render tree — the magic that makes it all tick!</p><p>Let’s pick up where we left off — and keep growing, branch by branch. 🌳</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*nygS6IsdI0nyaJsnQeQkEw.gif" /><figcaption><em>Well… that took a while, huh?</em></figcaption></figure><h3>Leaves in the Wind 🌱</h3><p>Last time, we explored the static structure of the view tree. But UIs aren’t static — they respond, evolve, and adapt. Now, it’s time to look at what happens when your view tree becomes dynamic.</p><p>SwiftUI lets us build flexible UIs using simple control structures like if, switch, or if let:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LJqjciw8FbiSt01cUWpm9g.jpeg" /></figure><p>This is called a <strong>conditional view</strong>. In the example above, the Image of the tree is always shown. The Text view, however, only appears when isTextVisible is true. If it’s false, the Text simply doesn’t appear.</p><p>But how does this work under the hood?</p><p>It’s all thanks to <a href="https://docs.swift.org/swift-book/documentation/the-swift-programming-language/opaquetypes/"><strong>opaque return types</strong></a> (some View). When you use some View, you’re telling Swift, “I’m returning a view, but I won’t tell you exactly which one.” This lets SwiftUI maintain type safety while giving you flexibility to swap between different views — without breaking the compiler or affecting performance.</p><blockquote>If you’re an Arabic speaker, check out the excellent <a href="https://youtu.be/sMurTGKNEbc?si=GJh8EvZVFgezzg7Q">opaque type</a>s video and <a href="https://youtube.com/playlist?list=PL1pN9hKJhcT6GjcY4PwqHq76AL_dWj3W1&amp;si=s0IZP05GDF8kLVzY">Asser’s great YouTube tutorial</a> on Swift 6.1</blockquote><p>This dynamic behavior is what allows SwiftUI views to adapt in real time, giving life to our apps. 🌱</p><h3>From Views to Nodes ⚙️</h3><p>In SwiftUI, the <strong>view tree</strong> is like a quick sketch — it’s built fast, used for a short time, and then thrown away whenever something changes in your app. This happens a lot, especially when your app’s state updates.</p><p>But behind the scenes, SwiftUI keeps something more lasting in memory. We can think of this as the <strong>render tree</strong>.</p><p>Now, the render tree isn’t something we see or work with directly. In fact, it doesn’t officially exist in SwiftUI. But it’s a helpful way to understand what’s really going on. The render tree is made of <strong>nodes</strong> — these are objects that SwiftUI holds onto and updates as needed.</p><p>To keep things clear:</p><ul><li>We say <strong>views</strong> when talking about the temporary elements in the view tree.</li><li>We say <strong>nodes</strong> when referring to their more permanent counterparts in the render tree.</li><li>The process of converting views into nodes is what we call <strong>rendering</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*gPIJ6qRj6Pa2BG-xdCDHig.gif" /></figure><h4>Toggling the Text</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*dOenRPFsd0F3T1KeuwHoeg.gif" /></figure><p>Let’s take a closer look at what happens when we toggle isTextVisible in this example:</p><p>The <strong>view tree</strong> always includes both subviews:</p><ul><li>An Image</li><li>A conditional Text view, which is part of the tree regardless of the isTextVisible value.</li></ul><p>Think of it like an optional: The view tree holds an Optional(Text(“Apple Tre”)). It’s still part of the structure, even if the value is nil.</p><p>What About the <strong>Render Tree</strong>?</p><p>The <strong>render tree</strong>, however, behaves differently. It only includes nodes that actually need to appear on screen.</p><p>When isTextVisible == false: The render tree contains just the VStack and the Image node.</p><p>When isTextVisible == true: SwiftUI updates the render tree to insert the Text node.</p><p>SwiftUI updates efficiently: it keeps the VStack and Image as-is and only adds or removes the Text based on the state.</p><h3><strong>Tree’s Lifetime Journey </strong>⏳</h3><p>When I first met SwiftUI, I came with my UIKit mindset.</p><p>I was ready — ready to handle every step of the view lifecycle:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*tq9PM1va6xUPX_Ey4QMMZg.jpeg" /></figure><p>But SwiftUI?</p><p>SwiftUI looked at me, smiled, and said:</p><p><em>“You don’t need to </em>manage<em>, just </em>declare<em> what you want — and I’ll take care of the rest.”</em></p><p>Suddenly, I wasn’t writing dozens of lifecycle hooks.</p><p>I had just a few:</p><ul><li>onAppear: run code when the view enters.</li><li>onDisappear: clean up when it exits.</li><li>task: kick off async work.</li><li>State &amp; Data Flow: Just hold the state — SwiftUI will do the rest(We’ll dive deeper into how it works in the next parts of this series.)</li></ul><p>This wasn’t just a lighter workflow…</p><p><strong>It was a whole new mindset.</strong></p><p>I stopped thinking about when to update the UI — and started thinking about what the UI <em>should be</em>, based on the state.</p><p>It’s like SwiftUI is the chill friend who handles all the complicated stuff while you just enjoy the ride! UIKit? Well, it’s like running a marathon with a backpack full of rocks.</p><blockquote>Want to dive deeper? Check out <a href="https://captainswiftui.substack.com/p/the-simple-lifecycle-of-a-swiftui">The Simple Life(cycle) of a SwiftUI View</a> and <a href="https://www.vadimbulavin.com/swiftui-view-lifecycle/">SwiftUI View Lifecycle</a> for more insights.</blockquote><p>And that’s a wrap for this part of our SwiftUI journey! We’ve explored how the view tree grows and changes, but there’s still a big secret waiting to be uncovered — <strong>value types and identity</strong>. It’s a topic so important, it deserves its own spotlight in the next part.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AdDhsfSW-ldj95IGtaZaDg.jpeg" /><figcaption>“Who is Spider-Man?” Well, just like us trying to figure out Peter Parker’s secret, SwiftUI needs to know which view is which to keep everything running smoothly! 🕷️</figcaption></figure><p>So, we’ll save that mystery for another day and keep this adventure fun and fresh.</p><p>Thanks for reading — until next time, keep coding and swinging through those apple trees!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d35ef1d6728" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apple Tree: The SwiftUI Way 1]]></title>
            <link>https://medium.com/@mmd57917/apple-tree-the-swiftui-way-1-d05f8495fed8?source=rss-1e2f33afc330------2</link>
            <guid isPermaLink="false">https://medium.com/p/d05f8495fed8</guid>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Mhmd Ebrahim]]></dc:creator>
            <pubDate>Sat, 21 Dec 2024 14:00:30 GMT</pubDate>
            <atom:updated>2024-12-21T14:00:30.620Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*_6jJo_Fkst_GoclXP6ukhg.gif" /></figure><h3>My First Lesson at 4Sale 🌱</h3><p>My current internship at <a href="https://www.q84sale.com/"><strong>4Sale International Co.</strong></a> is my first real experience working on a product in a professional environment. Those initial days were truly amazing!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*GCoAznL_RD5qOSGpAdt_ZQ.gif" /><figcaption>When David, the iOS Lead at 4Sale, introduced me to the team, I was filled with excitement and curiosity! Exploring the company and its culture left me wide-eyed and amazed, just like the video above 😄😄</figcaption></figure><p>The company’s product heavily relies on SwiftUI, so I was tasked with learning it. Coming from a UIKit background, this transition felt both fun and challenging, especially moving from an imperative to a declarative approach.</p><p>One day, while discussing SwiftUI with my friend Ahmed Ebrahim, an iOS developer at 4Sale, he shared something that stuck with me: “Writing SwiftUI isn’t just about syntax — it’s a mindset.” Those words ignited my curiosity. I remembered seeing a book titled <a href="https://www.objc.io/books/thinking-in-swiftui/"><strong>Thinking in SwiftUI</strong></a> and decided it was the perfect time to dive in.</p><h3><strong>From Code to Roots 🌳</strong></h3><p>SwiftUI’s core concept, <strong>view trees</strong>, immediately clicked for me. With a background in competitive programming, I’ve always loved trees — drawing them, using them in graphs, and solving puzzles with them. Discovering that SwiftUI structures its UI this way felt like connecting my past passions with my present challenges. It was exciting, familiar, and made perfect sense. The book <a href="https://www.objc.io/books/thinking-in-swiftui/"><strong>Thinking in SwiftUI</strong></a> focuses entirely on this approach, offering insights you won’t find elsewhere, which deepened my understanding even more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*Vsj_n_oij2jvIPb3.jpg" /></figure><p>In the first part of this series, we’ll explore the concept of the view tree in SwiftUI, diving into how it forms the foundation of UI design. In the subsequent parts, we’ll delve deeper into how this foundational concept intersects with other crucial aspects of SwiftUI, such as <strong>state</strong>, <strong>layout</strong>, <strong>animation</strong>, and much more.</p><h3><strong>View Tree: SwiftUI’s UI DNA 🌿</strong></h3><p>View trees in SwiftUI are the blueprint of your UI, organizing how views are structured, updated, and animated. Mastering them is key to efficient layouts, state management, and smooth transitions.</p><blockquote>View tree — or any concept we explore here — is just a mental model, a simplified map to help us visualize SwiftUI’s workings. Beneath the surface, SwiftUI’s internal processes are far more complex and involve much more than these conceptual “drawings”.</blockquote><h4><strong>Building the View Tree</strong> 🌿</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*PCGg0Ivtw6ZRIGtit_6NQA.gif" /></figure><p>Let’s break down this example:</p><p>When applying modifiers like .padding() and .background() in SwiftUI, each modifier wraps the view, building a hierarchical structure — similar to a tree in competitive programming.</p><p><strong>View Tree Structure: </strong>The view tree consists of the background as the root, padding<strong> </strong>as the child, and the Image as the leaf, with the green color being a child of the background.</p><p>In SwiftUI, modifiers are applied in the order they appear. Layout-related modifiers, like frame or padding, determine the root of the view tree and define the overall layout. Meanwhile, modifiers like background and overlay act as container-like modifiers, visually surrounding the original view and becoming the parent in the modifier hierarchy. Understanding this hierarchy helps predict both the layout and behavior of complex SwiftUI views.</p><h4><strong>Modifier Order: The Secret Sauce </strong>🧑‍🍳</h4><p>In SwiftUI, the order of your modifiers is like the order of ingredients in a recipe — mix them up, and the final dish will taste (or look) completely different. Each modifier wraps your view, building it step by step, and changing their sequence can totally alter the final result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*TFLxP4cqwDs_hVOS9LMIGQ.gif" /></figure><p>The order in which modifiers are applied is like the layers of a tree — each layer affects the final structure. The first modifier gives the foundation, and the last one creates the final touch. Stay tuned, as we’ll dig deeper into how this modifier sequence shapes your layout and behavior in future parts!</p><h3><strong>ViewBuilder: Crafting SwiftUI Views Like a Pro</strong> 🎨</h3><p>In SwiftUI, <a href="https://www.avanderlee.com/swiftui/viewbuilder"><strong>ViewBuilder</strong></a> is a powerful tool that simplifies the process of creating complex views. It lets you define a block of views declaratively, without needing explicit return statements or nested view creation. This makes SwiftUI code clean, readable, and intuitive.</p><p>You’ve likely used it without realizing it when working with SwiftUI containers like:</p><ul><li>VStack, HStack, ZStack</li><li>Modifiers like .background, .overlay</li></ul><blockquote>At its core, @ViewBuilder is powered by <a href="https://docs.swift.org/swift-book/documentation/the-swift-programming-language/advancedoperators#Result-Builders"><strong>ResultBuilder</strong></a>, a feature introduced in Swift 5.4. Think of ResultBuilder as the architect behind the scenes, helping you build views step-by-step in a natural way, like assembling the pieces of a grand design. It allows you to combine multiple expressions in one block, each representing a view, which makes writing SwiftUI code intuitive and straightforward.</blockquote><h4><strong>Rooting Views with ViewBuilder </strong>🌳</h4><p>One of the most important concepts in SwiftUI when using @ViewBuilder is the idea of <strong>view lists</strong>. Each ViewBuilder acts as the parent to a group of child views — think of it like a tree structure</p><ul><li>The parent is the container view</li><li>The children are the views inside</li></ul><p>For example, when you place multiple views inside a VStack, you’re creating a view list. This view list is represented by a tuple, with each child view being an element in the list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Up1_shVTkLMMChK3U6tUKw.jpeg" /></figure><h4>The Power of Parent and Child Modifiers 🧩</h4><p>The <strong>view list modifier</strong> refers to modifying the parent view and understanding how that modifier interacts with the entire list of child views (or each child individually). This behavior is influenced by how modifiers like .background, .padding, etc., interact with view containers such as VStack, HStack, or Group.</p><p><strong>Modifying the Entire View List (Parent Behavior): </strong>When you apply a modifier directly to a parent view like VStack, the modifier applies to the entire list of child views as a single group. This happens because SwiftUI treats the parent container (VStack or any container) as a single unit that holds all its child views.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UV3WOKpIpQMAqukbfczs8Q.jpeg" /></figure><p><strong>Behavior:</strong></p><ul><li>The .background(.green) modifier applies to the entir<strong>e </strong>VStack<strong> </strong>container, not just to the individual child views.</li><li>The .background becomes the parent view of the entire group of views.</li></ul><p><strong>Modifying Each Child Individually (Child Behavior): </strong>When you use a Group or a similar container that doesn’t enforce a specific layout behavior, the modifier is applied individually to each child view. This means the modifier affects each child view separately rather than the entire container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uHnTXVEuKtMl8ZCEe_irLg.jpeg" /></figure><p><strong>Behavior:</strong></p><ul><li>The Group doesn’t change the layout, so the .background(.green) modifier is applied to each individual child (Image, Text, Text)</li><li>Each child gets a green background<strong> </strong>individually</li></ul><blockquote>An exception occurs when a Group with modifiers is the root view or the only subview in a ScrollView, where it behaves like a VStack, applying modifiers to the entire group, not individual children. Similarly, placing a Group inside an overlay or background causes it to behave like a ZStack, altering its behavior.</blockquote><p>As your view lists grow, defining separate views can improve readability and modularity. By breaking the list into smaller components or structs, you make the code more maintainable and reusable.</p><p>That’s all for now! The world of SwiftUI is full of surprises, and this is just the beginning. Get ready for the next part of <em>Apple Tree</em> — exciting things are on the way. Thanks for reading!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*yseFhSJbf5606IDWm5ufjA.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d05f8495fed8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Art of Reusability:]]></title>
            <link>https://medium.com/@mmd57917/the-art-of-reusability-8df6cb8db3be?source=rss-1e2f33afc330------2</link>
            <guid isPermaLink="false">https://medium.com/p/8df6cb8db3be</guid>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[swift-package]]></category>
            <category><![CDATA[enum]]></category>
            <category><![CDATA[design]]></category>
            <dc:creator><![CDATA[Mhmd Ebrahim]]></dc:creator>
            <pubDate>Sun, 06 Oct 2024 15:44:03 GMT</pubDate>
            <atom:updated>2024-10-06T15:44:03.312Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Art of Reusability: How to Build a Reusable iOS Design System Package</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*tp8BeYV47TGz8l4877o7tQ.png" /></figure><p>Have you ever found yourself coding the same button for the 10th time this month? You tweak the padding, adjust the color, change the font — again and again. It’s a frustrating cycle that leads to what I like to call <strong>UI déjà vu</strong>.</p><p>But don’t worry, fellow developer! The answer to breaking this loop is simpler than you might think: <strong>a design system</strong>.</p><p>A design system provides a structured way to manage all those small but essential details — like design tokens (colors, typography, spacing) and reusable components (buttons, forms, etc.). Instead of starting from scratch every time you build a new feature, you’ll have a ready-to-go toolbox of beautifully standardized components.</p><p>Here’s the kicker: with design systems, you don’t have to reinvent the wheel. Once you build it, you can reuse it throughout your app, saving you hours of development time and countless headaches.</p><h3>Why Design Systems Matter: Unleashing the Power of Reusability</h3><p>Design systems are like the secret sauce in your coding kitchen, transforming the way you whip up applications. Here’s why they rock:</p><ul><li><strong>Efficiency</strong>: Wave goodbye to coding UI déjà vu and speed up your development process!</li><li><strong>Consistency</strong>: Bid farewell to design chaos and enjoy a seamless user experience!</li><li><strong>Maintenance Made Easy</strong>: Updating components? It’s as easy as pie!</li><li><strong>Scalability</strong>: Your design system grows alongside your app — flexibility at its finest!</li><li><strong>Cost Savings</strong>: Invest wisely now to reap savings later — your budget will thank you!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bMQ1XvJTxV30QVa4C3dfGg.png" /></figure><h3>The Essential Four Ingredients of Design Systems!</h3><p>These four key ingredients work together to create smooth, reusable UI components that elevate your design system:</p><ul><li><strong>Design Tokens: The Core Ingredients</strong></li><li><strong>Typography: The Design Voice</strong></li><li><strong>Color Palette: The Mood Setter</strong></li><li><strong>Measurements: The Precision Tools</strong></li></ul><h3>Swift Palette: Mastering the Art of Stylish, Reusable Components</h3><p>Now, gear up for the exciting part — the coding adventure awaits! Before we embark on this journey through the code jungle, let’s pause to appreciate the <strong>Core Ingredient</strong> that holds our design system together: <strong>Design Tokens</strong>.</p><p>Think of design tokens as the palette of colors and brushes for an artist. They are the fundamental units of a design system, capturing essential design decisions — colors, typography, spacing, and more.</p><h4>Let’s Build a Design System in iOS</h4><p>Now that we’ve set the stage, let’s jump into a real-world example: crafting a reusable, theme-aware design system within a Swift Package. Follow these steps to bring your design system to life in iOS:</p><h4>Step 1: Create a Swift Package</h4><p>Transform your design elements into a flexible toolkit by building a Swift package. Think of it like LEGO blocks — modular, reusable, and perfect for maintaining a consistent visual identity across projects.</p><ul><li>Open <strong>Xcode</strong> and select <strong>File &gt; New &gt; Swift Package</strong>.</li><li>Give your package a catchy name — how about <strong>SwiftPalette</strong>? Save it in your favorite directory.</li><li>The basic structure will be generated, including Package.swift — the brain of your package.</li></ul><h4>Step 2: Set Up Your Package.swift</h4><p>To enhance the modularity and reusability of your design system, we’ll customize the <strong>Package.swift</strong> file by specifying the platforms, products, and resources that your design system needs. Here’s an example configuration for our <strong>SwiftPalette</strong> package:</p><pre>let package = Package(<br>    name: &quot;SwiftPalette&quot;,<br>    platforms: [.iOS(.v17)],<br>    products: [<br><br>        .library(<br>            name: &quot;SwiftPalette&quot;,<br>            targets: [&quot;SwiftPalette&quot;]),<br>    ],<br>    targets: [<br> <br>        .target(<br>            name: &quot;SwiftPalette&quot;,<br>            resources: [<br>                .process(&quot;Resources&quot;)<br>            ]<br>        ),<br>    ]<br>)</pre><p>Adding .process(“Resources”) ensures that any resources — such as images, fonts, or other assets — are available for use in your Swift package.</p><h4>Step 3: Organize Your Swift Package Structure</h4><p>Now that your package is set up, let’s organize the structure to house your foundation, components, and resources:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*MZO-l03iEFxlz12X8YxAPA.png" /></figure><p>Here’s a breakdown of our design treasure:</p><p>1.<strong>Foundation Folder</strong>: This is the heart of your design system — colors, typography, spacing, and delightful extensions like UIColor+Hex. It’s where your design magic begins!</p><p>2.<strong>Components Folder</strong>: Home to your reusable components, like buttons and labels, witness the elegance of how effortlessly you can apply design tokens from the Foundation.</p><p>3.<strong>Resources Folder</strong>: Think of this as the attic where you keep all your visual treasures — images, JSON files, or any extra assets you need. While it’s not mandatory, it’s super handy!</p><h4>Step 4: Define Design Tokens in Enums</h4><p>Time to bring your design tokens to life in iOS with the magic of enums! Think of enums as the guiding stars of your design system — they eliminate confusion by providing clear, descriptive labels and enforce type safety, allowing only valid values. This prevents design hiccups and keeps your code neat, organized, and consistent.</p><p>Let’s define the core tokens for <strong>Colors</strong>, <strong>Typography</strong>, and <strong>Measurements</strong> using enums. These will form the backbone of your design system, ensuring that every component stays true to your style guide.</p><p>And don’t forget to make them <strong>public</strong> so they can be shared across different projects!</p><pre>public enum DesignSystem {<br>    public enum Colors {}<br>    public enum PrimaryFont {}<br>    public enum Measurements {}<br>}</pre><h4>Step 5: Color Palette — Setting the Mood</h4><p>Every great app starts with a strong color palette. A smart way to manage colors in iOS is by using an <strong>asset catalog</strong>, which supports both dark and light modes, ensuring a consistent experience across different display settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fXBX-Vzej37YsaudoNWW2g.png" /></figure><p>Once the colors are set in your assets, you can reference them in your DesignSystem.Colors enum like this:</p><pre>extension DesignSystem.Colors {<br>    public enum System {<br>        public static let fill = UIColor(named: &quot;Fill&quot;, in: .module, compatibleWith: nil)!<br>        public static let background = UIColor(named: &quot;Background&quot;, in: .module, compatibleWith: nil)!<br>        public static let label = UIColor(named: &quot;Label&quot;, in: .module, compatibleWith: nil)!<br>    }<br>    public enum SystemTints {<br>        public static let blue = UIColor(named: &quot;Blue&quot;, in: .module, compatibleWith: nil)!<br>        public static let green = UIColor(named: &quot;Green&quot;, in: .module, compatibleWith: nil)!<br>        public static let indigo = UIColor(named: &quot;Indigo&quot;, in: .module, compatibleWith: nil)!<br>        public static let orange = UIColor(named: &quot;Orange&quot;, in: .module, compatibleWith: nil)!<br>        public static let pink = UIColor(named: &quot;Pink&quot;, in: .module, compatibleWith: nil)!<br>        public static let purple = UIColor(named: &quot;Purple&quot;, in: .module, compatibleWith: nil)!<br>        public static let red = UIColor(named: &quot;Red&quot;, in: .module, compatibleWith: nil)!<br>        public static let yellow = UIColor(named: &quot;Yellow&quot;, in: .module, compatibleWith: nil)!<br>    }<br>}</pre><p>The (in: .module) tells your project to fetch these resources from your fabulous Swift package, letting you use assets seamlessly across the board.</p><h4>Step 6: Typography — The Design Voice</h4><p>Fonts are more than just letters — they’re the voice of your design. Choosing the right typography gives your app its personality, whether it’s professional, fun, or bold.</p><p>Here’s how we can define some fonts in <strong>SwiftPalette:</strong></p><pre>extension DesignSystem.PrimaryFont {<br>    public static let smRegular = UIFont(name: &quot;JetBrainsMono-Regular&quot;, size: 19)<br>    public static let smBold = UIFont(name: &quot;JetBrainsMono-Bold&quot;, size: 19)<br>    <br>    public static let mdRegular = UIFont(name: &quot;JetBrainsMono-Regular&quot;, size: 21)<br>    public static let mdBold = UIFont(name: &quot;JetBrainsMono-Bold&quot;, size: 22)<br>    <br>    public static let lgRegular = UIFont(name: &quot;JetBrainsMono-Regular&quot;, size: 22)<br>    public static let lgBold = UIFont(name: &quot;JetBrainsMono-Bold&quot;, size: 22)<br>}</pre><p>If you’re using custom fonts, place them in the Resources folder and ensure they’re properly registered:</p><pre>extension UIFont {<br>    static func registerCustomFonts() {<br>        guard let url = Bundle.module.url(/service/forresource: &quot;JetBrainsMono-Regular&quot;, withExtension: &quot;ttf&quot;),<br>              let fontData = try? Data(contentsOf: url),<br>              let provider = CGDataProvider(data: fontData as CFData),<br>              let font = CGFont(provider) else { return }<br>        <br>        CTFontManagerRegisterGraphicsFont(font, nil)<br>    }<br>}<br>UIFont.registerCustomFonts()  // Call this in your AppDelegate or before using the font</pre><p>This code ensures that your fonts are accessible and can be applied throughout any project that uses SwiftPalette.</p><h4>Step 7: Measurements — Crafting the Layout</h4><p>Consistency is key when it comes to layout. Defining <strong>measurements</strong> for spacing and corner radius ensures every UI element looks cohesive.</p><p>Here’s how you can structure the Measurements enum:</p><pre>extension DesignSystem.Measurements {<br>    public enum CornerRadius {<br>        public static let sm: CGFloat = 4.0<br>        public static let md: CGFloat = 8.0<br>        public static let lg: CGFloat = 16.0<br>    }<br>    <br>    public enum Spacing {<br>        public static let sm: CGFloat = 8.0<br>        public static let md: CGFloat = 16.0<br>        public static let lg: CGFloat = 24.0<br>    }<br>}</pre><h4>Step 8: Combine It All to Build a Reusable Primary Button</h4><p>Now that we’ve defined the key components of our design system (colors, typography, and spacing), let’s create a reusable <strong>Primary Button</strong> component using these tokens:</p><pre>public class PrimaryButton: UIButton {<br>    <br>    override init(frame: CGRect) {<br>        super.init(frame: frame)<br>        setup()<br>    }<br>    <br>    required init?(coder: NSCoder) {<br>        super.init(coder: coder)<br>        setup()<br>    }<br>    <br>    func setup() {<br>        self.setTitle(&quot;Primary Button&quot;, for: .normal)<br>        self.setTitleColor(DesignSystem.Colors.System.label, for: .normal)<br>        self.backgroundColor = DesignSystem.Colors.System.fill<br>        self.titleLabel?.font = DesignSystem.PrimaryFont.smRegular<br>        self.layer.cornerRadius = DesignSystem.Measurements.CornerRadius.lg<br>    }<br>}</pre><h4>Step 9: Create Reusable Components</h4><p><strong>Let’s sprinkle some magic into your Xcode project with the Swift package — SwiftPalette! Here’s how to add it:</strong></p><ol><li>Open your Xcode project and select your project in the Project Navigator.</li><li>Go to the Package Dependencies section and click the “+” button.</li><li>Paste the URL: <a href="https://github.com/M7md-Ebrahim/SwiftPalette.git">https://github.com/M7md-Ebrahim/SwiftPalette.git</a>, select version <strong>1.0.0</strong>, and click <strong>Add Package</strong>.</li></ol><p>Now, import it and let the fun begin with your design tokens and components:</p><pre>import UIKit<br>import SwiftPalette<br><br>class HomeViewController: UIViewController {<br>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        view.backgroundColor = DesignSystem.Colors.System.background<br>        let primaryButton = PrimaryButton()<br>        view.addSubview(primaryButton)<br>    }</pre><p>🎉 <strong>Boom!</strong> We’ve just created a button that checks all the boxes:</p><ul><li><strong>Color</strong>: Dynamically adapts to light and dark modes.</li><li><strong>Typography</strong>: Uses our consistent font styling.</li><li><strong>Corner Radius</strong>: Looks sleek and modern thanks to predefined values.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UtpoSid4QckXqSN7u68roQ.jpeg" /></figure><p>🎉 Congrats! You’ve just created a sleek, reusable Swift package with SwiftPalette. Whether it’s color, typography, or components, you’ve got a robust toolkit to keep your designs consistent, stylish, and easy to use across projects. Time to unleash your inner design wizard!</p><p>In conclusion, a design system is not a one-time effort but a living entity that evolves, ensuring ongoing improvements and scalability. Because your application is powered by the reusable components of your system, it automatically inherits improvements, significantly lowering the effort required to maintain the application. This is the power of scaling that a design system offers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8df6cb8db3be" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>