<?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 Mouna on Medium]]></title>
        <description><![CDATA[Stories by Mouna on Medium]]></description>
        <link>https://medium.com/@khmMouna?source=rss-f925904d66c4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VG-Q6FQBCrFEwIX0oDnQDA.jpeg</url>
            <title>Stories by Mouna on Medium</title>
            <link>https://medium.com/@khmMouna?source=rss-f925904d66c4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 22:48:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@khmMouna/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[Swift: Combining multiple publishers : Merge/CombineLatest/Zip]]></title>
            <link>https://medium.com/code-with-me/swift-combining-multiple-publishers-merge-combinelatest-zip-5fe36bf8227b?source=rss-f925904d66c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5fe36bf8227b</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[combine]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Mouna]]></dc:creator>
            <pubDate>Tue, 05 Dec 2023 11:16:18 GMT</pubDate>
            <atom:updated>2023-12-05T13:03:37.925Z</atom:updated>
            <content:encoded><![CDATA[<h3>Swift: Combining multiple publishers : Merge/CombineLatest/Zip</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iONzmnn_ZcBudQwC4bBN6g.jpeg" /></figure><p>Combine is a framework in Swift for processing values over time. Today I want to talk about running multiple operations in parallel and handing results in a single place. When you want to combine the output from multiple publishers, you can use various operators provided by Combine. Here’s a brief overview of how you can combine multiple publishers in Swift using Combine:</p><h3>Merge:</h3><p>The merge operator combines the elements from multiple publishers into a single publisher. You can use mergeto merge different publishers with the same output type.</p><pre>import Combine<br><br>let publisher1 = PassthroughSubject&lt;Int, Never&gt;()<br>let publisher2 = PassthroughSubject&lt;Int, Never&gt;()<br><br>let merged = Publishers.Merge(publisher1, publisher2)<br><br>let cancellable = merged.sink { value in<br>    print(value)<br>}<br><br>publisher1.send(1)<br>publisher2.send(2)<br><br>// Output: 1, 2</pre><h3>CombineLatest:</h3><p>The combineLatest operator do the same thing as merge but can merge different publishers with the different output types.</p><pre>import Combine<br><br>let publisher1 = PassthroughSubject&lt;Int, Never&gt;()<br>let publisher2 = PassthroughSubject&lt;String, Never&gt;()<br><br>let combined = Publishers.CombineLatest(publisher1, publisher2)<br><br>let cancellable = combined.sink { value in<br>    print(value)<br>}<br><br>publisher1.send(1)<br>publisher2.send(&quot;A&quot;)<br><br>// Output: (1, &quot;A&quot;)</pre><h3>Zip:</h3><p>The zip operator combines elements from multiple publishers into tuples. You can use zip operator when you have a couple of publishers and need to wait for values from all of them. The main downside of the zip operator is that it delivers values only when all the publishers emit.</p><pre>import Combine<br><br>let publisher1 = PassthroughSubject&lt;Int, Never&gt;()<br>let publisher2 = PassthroughSubject&lt;String, Never&gt;()<br><br>let zipped = Publishers.Zip(publisher1, publisher2)<br><br>let cancellable = zipped.sink { value in<br>    print(value)<br>}<br><br>publisher1.send(1)<br>publisher2.send(&quot;A&quot;)<br><br>// Output: (1, &quot;A&quot;)</pre><p>These are just a few examples of combining publishers in Combine. Depending on your use case, you may choose the appropriate operator that best fits your requirements. Additionally, Combine provides many other operators for transforming, filtering, and manipulating values from publishers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5fe36bf8227b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-with-me/swift-combining-multiple-publishers-merge-combinelatest-zip-5fe36bf8227b">Swift: Combining multiple publishers : Merge/CombineLatest/Zip</a> was originally published in <a href="https://medium.com/code-with-me">Code with me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[@unknown default usage with enums in Swift]]></title>
            <link>https://medium.com/code-with-me/unknown-default-usage-with-enums-in-swift-08bfd6f46080?source=rss-f925904d66c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/08bfd6f46080</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[objective-c]]></category>
            <category><![CDATA[enum]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Mouna]]></dc:creator>
            <pubDate>Thu, 30 Nov 2023 11:02:33 GMT</pubDate>
            <atom:updated>2023-12-05T13:07:19.003Z</atom:updated>
            <content:encoded><![CDATA[<h3>Swift: @unknown default</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iONzmnn_ZcBudQwC4bBN6g.jpeg" /></figure><h3>Objective-c enum:</h3><p>In objective-c, the enumerated type is simply a specific list of integers, where each value is given a name.</p><pre>// MyEnum.h<br>#import &lt;Foundation/Foundation.h&gt;<br><br>typedef NS_ENUM(NSInteger, Direction) {<br>    north,<br>    south,<br>    east,<br>    west<br>};</pre><h3>Swift enum:</h3><p>Swift comes with more flexible enum. Enums values can be a string, character, any integer or floating point type. Enums can have computed properties, initializers, instance functions and can also conform to protocols.</p><pre>enum Direction {<br>    case north<br>    case south<br>    case east<br>    case west<br>}</pre><p>Now, there are two types of enums ie. <strong>frozen</strong> and <strong>non-frozen</strong> enums.</p><ul><li><strong>frozen</strong> enum is an enum that may not gain new cases in the future.</li><li><strong>non-frozen</strong> enum is an enum to which new enumeration cases can be added in the future and any code which interacts with that enumeration should be able to handle the future cases without being recompiled.</li></ul><blockquote>The user-defined Swift enums are considered <strong>frozen. </strong>Only the standard library, Swift overlays for Apple frameworks, and C and Objective-C code can declare nonfrozen enumerations.</blockquote><p>When using a <strong>non-frozen</strong> enum we should add a default case even if every case of the enum has a corresponding switch case, to helps us to prepare for future changes.</p><p>To achieve that we need to use <strong>@unknown default.</strong></p><pre>switch applicationState {<br>case .active:<br>  //<br>case .inactive:<br>              //<br>case .background:<br>  //<br>@unknown default:<br>  //<br>}</pre><blockquote>The downside of using a default case is that the compiler can no longer alert a developer that a particular enum has elements that aren&#39;t explicitly handled in the switch. To remedy this, switch cases will gain a new attribute, @unknown.</blockquote><blockquote>Like the regular default, @unknown default matches any value; it is a &quot;catch-all&quot; case. However, the compiler will produce a <em>warning</em> if all known elements of the enum have not already been matched. This is a warning rather than an error so that adding new elements to the enum remains a source-compatible change. (This is also why @unknown default matches any value rather than just those not seen at compile-time.)</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=08bfd6f46080" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-with-me/unknown-default-usage-with-enums-in-swift-08bfd6f46080">@unknown default usage with enums in Swift</a> was originally published in <a href="https://medium.com/code-with-me">Code with me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DocC]]></title>
            <link>https://medium.com/code-with-me/docc-3aefd0bf38d1?source=rss-f925904d66c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3aefd0bf38d1</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[documentation]]></category>
            <category><![CDATA[docc]]></category>
            <category><![CDATA[github-pages]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Mouna]]></dc:creator>
            <pubDate>Mon, 27 Nov 2023 10:55:55 GMT</pubDate>
            <atom:updated>2023-11-27T10:55:55.817Z</atom:updated>
            <content:encoded><![CDATA[<p>DocC produces rich API reference <strong>documentation</strong> and interactive <strong>tutorials</strong> for our framework or package.</p><p>The DocC documentation compiler converts Markdown-based text into rich documentation for Swift frameworks and packages.</p><p>You can preview the documentation in its published form as you work on it, and also host it on a website when it’s complete.</p><h3><strong>Why DocC ?</strong></h3><ul><li>Developers are used to using it since it matches Apple API docs.</li><li>More detailed docs.</li><li>Can add Tutorials.</li><li>Easy to generate.</li><li>Support GitHub Pages integration.</li></ul><h3><strong>How to build and archive documentation?</strong></h3><h4>Manually:</h4><ul><li>To compile the documentation, we have to build the project. DocC consumes that information and compiles the documentation into a <strong>DocC Archive</strong>.</li><li>This process repeats for every framework or package your target depends on.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XGDKHohyAXCaqyLp" /></figure><p>To build documentation manually, choose <strong>Product &gt; Build Documentation</strong>. DocC compiles the documentation and opens it in Xcode’s documentation viewer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*PjepREhFbPcFnp1mIu6ttA.png" /></figure><h4><strong>From command line:</strong></h4><pre>xcodebuild docbuild<br>-scheme scheme<br>-derivedDataPath OUTPUT<br>-destination &#39;platform=iOS Simulator,name=iPhone 13&#39;</pre><h3><strong>Host the documentation on a server</strong></h3><ul><li>You can share your generated documentation, either directly with Xcode users who open it in the documentation viewer, or by hosting it on a website.</li><li>If you are fan with github, you can deploy the generated doc to <strong>GitHub Pages.</strong></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3aefd0bf38d1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-with-me/docc-3aefd0bf38d1">DocC</a> was originally published in <a href="https://medium.com/code-with-me">Code with me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift: Public getter and Private setter]]></title>
            <link>https://medium.com/code-with-me/swift-public-getter-and-private-setter-a3f323bfc5fa?source=rss-f925904d66c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3f323bfc5fa</guid>
            <dc:creator><![CDATA[Mouna]]></dc:creator>
            <pubDate>Fri, 24 Nov 2023 11:16:52 GMT</pubDate>
            <atom:updated>2023-12-05T13:06:22.277Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iONzmnn_ZcBudQwC4bBN6g.jpeg" /></figure><p>By default, property is internal. This means the property is accessible/settable from the module and not from outside.</p><p>Adding keyword <strong>public </strong>will make the property accessible/settable from outside the module.</p><p>Sometime we want a property to be publicly accessible but not settable.</p><p>How we can achieve that?</p><p>In swift, we have an easy way to do it:</p><pre>class MyClass {<br>    <br>    public private(set) var myProperty: String = &quot;&quot;<br>    <br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3f323bfc5fa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-with-me/swift-public-getter-and-private-setter-a3f323bfc5fa">Swift: Public getter and Private setter</a> was originally published in <a href="https://medium.com/code-with-me">Code with me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Grid-SwiftUI]]></title>
            <link>https://medium.com/code-with-me/grid-swiftui-c91cf8c7b57b?source=rss-f925904d66c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/c91cf8c7b57b</guid>
            <category><![CDATA[swiftui-3]]></category>
            <category><![CDATA[ios-developer]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Mouna]]></dc:creator>
            <pubDate>Mon, 04 Jul 2022 14:06:50 GMT</pubDate>
            <atom:updated>2023-12-04T17:08:05.545Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*t2F7-jrZgg6h9o6t5iOGOg.png" /></figure><p>Grid is a container view that arranges other views in a two-dimensional layout (horizontal and vertical).</p><p>Let’s have some examples:</p><ol><li><strong>Sample grid:</strong></li></ol><p>In this example we are going to display a grid with only 2 rows.</p><p>Use one or more GridRow instances to define the rows of a <a href="https://developer.apple.com/documentation/swiftui/grid">Grid</a> container.</p><pre>Grid {<br>            /// The first row<br>            GridRow {<br>                Text(&quot;Row 1&quot;)<br>                ForEach(0..&lt;3) { _ in Color.red }<br>            }<br>            /// The second row<br>            GridRow {<br>                Text(&quot;Row 2&quot;)<br>                ForEach(0..&lt;4) { _ in Color.green }<br>            }<br>            /// The third row<br>            GridRow {<br>                Text(&quot;Row 3&quot;)<br>                ForEach(0..&lt;4) { _ in Color.blue }<br>            }<br>        }<br>        .padding()<br>        .frame(height: 300)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rx3gAprcjhmUjQCf5KHRlg.png" /></figure><p>2. <strong>Collection view:</strong></p><p>In this example, we are going to use <strong>LazyVGrid</strong> to create a collection view.</p><pre>/* Copyright AFAR and Contributors */</pre><pre>import SwiftUI</pre><pre>struct AfarListView: View {<br>    <br>    let columns = [<br>        GridItem(.flexible()),<br>        GridItem(.flexible())<br>    ]<br>    var body: some View {<br>        ScrollView {<br>            LazyVGrid(columns: columns, spacing: 20) {<br>                ForEach(afarList, id: \.self) { item in<br>                    AfarItem(afarItem: item)<br>                }<br>            }<br>            .padding(.horizontal)<br>        }<br>        .background(Color(&quot;backGroundColor&quot;))<br>    }<br>}</pre><pre>struct AfarItem: View {<br>    var afarItem: AfarModel<br>    var body: some View {<br>        ZStack {<br>            Color<br>                .white<br>            VStack(alignment: .leading) {<br>                ZStack {<br>                    Image(afarItem.thumb)<br>                        .resizable()<br>                        .scaledToFit()<br>                        .frame(height: 120)<br>                        .clipped()<br>                }<br>                Text(afarItem.title)<br>                    .foregroundColor(.black)<br>                Spacer()<br>                HStack {<br>                    Text(&quot;9 min&quot;)<br>                        .foregroundColor(.gray)<br>                    Spacer()<br>                    Text(&quot;2.6 km&quot;)<br>                        .foregroundColor(.gray)<br>                }<br>            }<br>            .padding()<br>        }<br>        .cornerRadius(20)<br>    }<br>}</pre><pre>struct AfetListView_Previews: PreviewProvider {<br>    static var previews: some View {<br>        AfarListView()<br>    }<br>}</pre><p>My <strong>AfarModel </strong>looks like that:</p><pre>/* Copyright AFAR and Contributors */</pre><pre>import Foundation</pre><pre>struct AfarModel: Hashable {<br>    var thumb: String<br>    var title: String<br>}</pre><pre>/// TODO this list is used for test only for the moment<br>var afarList = [<br>    AfarModel(thumb: &quot;lit&quot;, title: &quot;Lit&quot;),<br>    AfarModel(thumb: &quot;canape&quot;, title: &quot;canapé&quot;),<br>    AfarModel(thumb: &quot;table&quot;, title: &quot;table&quot;),<br>    AfarModel(thumb: &quot;bureau&quot;, title: &quot;bureau&quot;),<br>    AfarModel(thumb: &quot;sac&quot;, title: &quot;sac&quot;),<br>    AfarModel(thumb: &quot;meuble tv&quot;, title: &quot;meuble tv&quot;)),<br>    AfarModel(thumb: &quot;aspirateur&quot;, title: &quot;aspirateur&quot;)<br>]</pre><p>Then, you need just to add your assets to the project.</p><p>That’s it for the grid !!!!</p><p>Your collection is created with a few lines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JoLHyDLnyFQb_5ezjgjzAA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c91cf8c7b57b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-with-me/grid-swiftui-c91cf8c7b57b">Grid-SwiftUI</a> was originally published in <a href="https://medium.com/code-with-me">Code with me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SwiftUI: TabView]]></title>
            <link>https://medium.com/code-with-me/tabview-swiftui-5ba92e1211fa?source=rss-f925904d66c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ba92e1211fa</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Mouna]]></dc:creator>
            <pubDate>Fri, 01 Jul 2022 16:08:10 GMT</pubDate>
            <atom:updated>2023-12-04T17:03:41.084Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*t2F7-jrZgg6h9o6t5iOGOg.png" /></figure><p>Create a new SwiftUI View, we will call it <strong>AfarTabBar.</strong></p><p>We are going to use <strong>TabView </strong>component</p><pre>TabView {<br>}</pre><p>Then we are going to use <strong>tabItem() </strong>modifier to add an icon and text for each view.</p><pre>TabView {<br>            Color(.red)<br>                .tabItem {<br>                    Label(&quot;List&quot;, systemImage: &quot;list.dash&quot;)<br>                }<br>            Color(.blue)<br>                .tabItem {<br>                    Label(&quot;Create&quot;, systemImage: &quot;plus.circle&quot;)<br>                }<br>            Color(.green)<br>                .tabItem {<br>                    Label(&quot;Messages&quot;, systemImage: &quot;message.circle&quot;)<br>                }<br>            Color(.yellow)<br>                .tabItem {<br>                    Label(&quot;Profile&quot;, systemImage: &quot;person.circle&quot;)<br>                }<br>        }<br>    }</pre><p>Here I used<strong> </strong><strong>Color </strong>to avoid creating views for my test.</p><p>That’s it !!!!</p><p>Now, let’s run the app now</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WCS7iv8zoZwbMUVx9Xg33w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ba92e1211fa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-with-me/tabview-swiftui-5ba92e1211fa">SwiftUI: TabView</a> was originally published in <a href="https://medium.com/code-with-me">Code with me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift concurrency — part 1]]></title>
            <link>https://medium.com/code-with-me/swift-concurrency-part-1-690d2854f7fe?source=rss-f925904d66c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/690d2854f7fe</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[concurrency]]></category>
            <dc:creator><![CDATA[Mouna]]></dc:creator>
            <pubDate>Thu, 23 Jun 2022 12:56:18 GMT</pubDate>
            <atom:updated>2023-12-04T17:10:47.140Z</atom:updated>
            <content:encoded><![CDATA[<h3>Swift: concurrency — part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iONzmnn_ZcBudQwC4bBN6g.jpeg" /></figure><p>The term <strong>currency</strong> is always linked with †he use of <strong>parallel code</strong>. Let’s see what these two words mean. It’s important to understand where and how they could be used.</p><p>When we run a list of tasks on a computer:</p><ul><li><strong>Case 1: The computer has only one core:</strong> When we run a list of tasks, for example, open a photo, play music … Then, the system will execute them one by one because they have a single-core CPU, but to the user, it seems like they are executed simultaneously. That’s called <strong><em>concurrency</em></strong><em>. The </em>CPU core can switch quickly between the different programs so they appear to be running at the same time, but what is really happening is that one task progress on its work then pauses so that another one can start, make some progress, then pause, and so on.</li><li><strong>Case 2: The computer has more than one single-core CPU: </strong>As soon as you add another CPU core to a computer, then things can run in <strong><em>parallel</em></strong>. This means multiple programs run simultaneously — for example, a computer with a four-core processor can run four pieces of code at the same time, with each core carrying out one of the tasks. As you might imagine, this means work can happen faster because four programs can run at the same time.</li></ul><p>Now that we know what currency means. Let’s discover <strong>swift currency</strong>.</p><h3>Swift concurrency</h3><p>The <strong>concurrency</strong> model in Swift is built on top of threads, but you don’t interact with them directly.</p><p>An <strong>asynchronous</strong> function in Swift can give up the thread that it’s running on, which lets another asynchronous function run on that thread while the first function is blocked. Swift doesn’t make any guarantee about which thread that function will run on.</p><blockquote>The new SwiftUI API is shared across iOS, tvOS, watchOS, macCatalyst, and Widgets.</blockquote><blockquote>It is only available in iOS 13.0.0 or newer</blockquote><h3>Why Swift <strong>concurrency</strong>?</h3><ul><li>Swift currency exposes a clear API, that makes the code more sample and easy to understand.</li><li>Uses <strong>async</strong> function → Good bye completion handler and blocks.</li><li>Uses actors to guarantee safe access to data.</li></ul><h3>Example</h3><p>Create an async function:</p><pre><strong>func</strong> retrieveMessageList() <strong>async</strong> <strong>throws</strong> -&gt; [String] {<br>        //The Task.sleep method does nothing,<br>        //but waits at the given number of nanoseconds <br>        //before it returns.<br>        //This method is useful when writing simple code<br>        // to learn how concurrency works<br>        try await Task.sleep(until: .now + .seconds(3), clock: .continuous)<br>        return [&quot;L1G001&quot;, &quot;L1G002&quot;, &quot;L1G003&quot;, &quot;L1G004&quot;]<br>    }</pre><p>Then you can use it:</p><pre><strong>do</strong> {<br>    let messages = <strong>try</strong> <strong>await</strong> test.retrieveMessageList()<br>    print(&quot;My message list is \(messages)&quot;)<br>} <strong>catch</strong> {<br>    print(&quot;Unable to retrieve the list of message \(error.localizedDescription)&quot;)<br>}</pre><p>Let’s analyze the code now:</p><ul><li><strong>async: </strong>is a keyword used to indicate that a function is asynchronous.</li><li><strong>await</strong>: is a keyword used to wait for an async method.</li><li><strong>Throws</strong>: is a keyword used to mark a throwing function. For a function that’s both asynchronous and throwing, you write async before throws.</li><li><strong>do/try/catch</strong>: These keywords are used together to handle a throwing function.</li></ul><blockquote><em>With that, we have reached the end of this article.</em></blockquote><blockquote><em>Thank you once again for reading.</em></blockquote><blockquote><em>Don’t forget to 👏 and follow 😍.</em></blockquote><h4><strong>Coming soon. Wait for it</strong></h4><blockquote><strong>Asynchronous Sequences</strong></blockquote><blockquote><strong>Calling Asynchronous Functions in Parallel</strong></blockquote><blockquote><strong>Tasks and Task Groups</strong></blockquote><blockquote><strong>Unstructured Concurrency</strong></blockquote><blockquote><strong>Task Cancellation</strong></blockquote><blockquote><strong>Actors</strong></blockquote><blockquote><strong>Sendable Types</strong></blockquote><p><strong>References:</strong></p><ul><li><a href="https://developer.apple.com/videos/play/wwdc2022/10142/">Efficiency awaits: Background tasks in SwiftUI - WWDC22 - Videos - Apple Developer</a></li><li><a href="https://www.hackingwithswift.com/quick-start/concurrency/concurrency-vs-parallelism">Concurrency vs parallelism</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=690d2854f7fe" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-with-me/swift-concurrency-part-1-690d2854f7fe">Swift concurrency — part 1</a> was originally published in <a href="https://medium.com/code-with-me">Code with me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Charts-Swift]]></title>
            <link>https://medium.com/code-with-me/charts-swift-47d7f9984a7b?source=rss-f925904d66c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/47d7f9984a7b</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[charts]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[ios-development]]></category>
            <dc:creator><![CDATA[Mouna]]></dc:creator>
            <pubDate>Sun, 19 Jun 2022 22:28:30 GMT</pubDate>
            <atom:updated>2023-12-04T17:01:52.193Z</atom:updated>
            <content:encoded><![CDATA[<h3>SwiftUI: Charts</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*t2F7-jrZgg6h9o6t5iOGOg.png" /></figure><p>Charts are powerful tools for making your application more informative.</p><p>Apple announced the new Swift Chart kit within WWDC22. <strong>Swift charts </strong>is a flexible framework for making Apple-designed charts.</p><h3>How to design a chart?</h3><p>The chart design process involves five topics:</p><ul><li>Marks: which are a chart’s visual building blocks. It can be bars, line, point… It is also extensible and can add custom marks.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*GdiYmmUnA2OFBQO-JZK80g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*yZlVkeqzDZ0JXevu0SG-Fw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*n9XtXxsUFpaO-hgEfkT8Fg.png" /><figcaption>Marks</figcaption></figure><ul><li>Axes: The x and y properties.</li><li>Description: It’s the text preceding the chart, to provide context.</li><li>Interaction: Empower deeper exploration of data and is critical to accessibility.</li><li>Color: Use color to make the chart easier to understand.</li></ul><h3>Complete example</h3><p>Let’s create a bar chart that represents the data for a student survey of favorite types of drinks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*vYTiQsnFwiuF-lZ6JtkuCw.png" /></figure><p>We will start by creating the struct <strong>Drink:</strong></p><pre>struct Drink: Identifiable {<br>    var type: String<br>    var count: Double<br>    var id = UUID()<br>}</pre><p>Then we will initialize an array of Drink structures to hold the data from the table:</p><pre>var data: [Drink] = [<br>        .init(type: &quot;Milk&quot;, count: 5),<br>        .init(type: &quot;Soda&quot;, count: 8),<br>        .init(type: &quot;Water&quot;, count: 12),<br>        .init(type: &quot;Juice&quot;, count: 7),<br>        .init(type: &quot;Thea&quot;, count: 5),   <br>]</pre><p>Now, let’s create the chart component</p><pre>Chart(data) { drink in<br>    BarMark(<br>        x: .value(&quot;Drink Type&quot;, drink.type),<br>        y: .value(&quot;Total Count&quot;, drink.count)<br>    )<br>}</pre><p>Finally, let’s run and see what it looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*5vLTDG38Y8rnye4no3dd5w.png" /></figure><p>Nice work, it’s really sample.</p><p>Now let’s improve the appearance. Let’s add additional properties like color</p><p>The Drink will become</p><pre>struct Drink: Identifiable {<br>    var color: String<br>    var type: String<br>    var count: Double<br>    var id = UUID()<br>}</pre><p>Then update the data array to add the color information</p><pre>var data: [Drink] = [<br>        .init(color: &quot;Green&quot;, type: &quot;Milk&quot;, count: 5),<br>        .init(color: &quot;Green&quot;, type: &quot;Soda&quot;, count: 8),<br>        .init(color: &quot;Green&quot;, type: &quot;Water&quot;, count: 12),<br>        .init(color: &quot;Green&quot;, type: &quot;Juice&quot;, count: 7),<br>        .init(color: &quot;Green&quot;, type: &quot;Thea&quot;, count: 5),<br>        .init(color: &quot;Yellow&quot;, type: &quot;Milk&quot;, count: 7),<br>        .init(color: &quot;Yellow&quot;, type: &quot;Soda&quot;, count: 4),<br>        .init(color: &quot;Yellow&quot;, type: &quot;Water&quot;, count: 9),<br>        .init(color: &quot;Yellow&quot;, type: &quot;Juice&quot;, count: 2),<br>        .init(color: &quot;Yellow&quot;, type: &quot;Thea&quot;, count: 3),<br>        .init(color: &quot;Pink&quot;, type: &quot;Milk&quot;, count: 5),<br>        .init(color: &quot;Pink&quot;, type: &quot;Soda&quot;, count: 3),<br>        .init(color: &quot;Pink&quot;, type: &quot;Water&quot;, count: 8),<br>        .init(color: &quot;Pink&quot;, type: &quot;Juice&quot;, count: 4),<br>        .init(color: &quot;Pink&quot;, type: &quot;Thea&quot;, count: 8)<br>    ]</pre><p>To represent this additional dimension of information, add the foregroundStyle method to the BarMark, and indicate the data’s color property as the plottable value:</p><pre>Chart(data) { drink in<br>    BarMark(<br>        x: .value(&quot;Drink Type&quot;, drink.type),<br>        y: .value(&quot;Total Count&quot;, drink.count)<br>    )<br>    .foregroundStyle(by: .value(&quot;Drink Color&quot;, drink.color))<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*gmYr4KLtL4FS8sWBMzQShg.png" /></figure><p>Now, you can customize the chart to override the default color scale by adding the chatForegroundStyleScalechart modifier:</p><pre>Chart(data) { drink in<br>    BarMark(<br>        x: .value(&quot;Drink Type&quot;, drink.type),<br>        y: .value(&quot;Total Count&quot;, drink.count)<br>    )<br>    .foregroundStyle(by: .value(&quot;Drink Color&quot;, drink.color))<br>}<br>.chartForegroundStyleScale([<br>    &quot;Green&quot;: .green, &quot;Yellow&quot;: .yellow, &quot;Pink&quot;: .pink<br>])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*Ka3Efb4qjyiOHbnVnCUqvg.png" /></figure><p><strong>That’s it !</strong></p><p><strong>Thank you for your attention !!!!</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FBYoRqTmcgzHcL9TCy1%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FBYoRqTmcgzHcL9TCy1%2Fgiphy.gif&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExeTloZWNvMHpraDU0YzdrazVweHBqcDgxMWc0MDF5ZHI2ODN5cmwzZSZlcD12MV9naWZzX2dpZklkJmN0PWc%2FBYoRqTmcgzHcL9TCy1%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/517bbcb5e5f7c514ca9999f7aae1528b/href">https://medium.com/media/517bbcb5e5f7c514ca9999f7aae1528b/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47d7f9984a7b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-with-me/charts-swift-47d7f9984a7b">Charts-Swift</a> was originally published in <a href="https://medium.com/code-with-me">Code with me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to customize your file header text in Xcode]]></title>
            <link>https://medium.com/code-with-me/how-to-customize-your-file-header-text-in-xcode-3876c006548c?source=rss-f925904d66c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3876c006548c</guid>
            <category><![CDATA[ios-developer]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios-development]]></category>
            <dc:creator><![CDATA[Mouna]]></dc:creator>
            <pubDate>Fri, 17 Jun 2022 22:47:42 GMT</pubDate>
            <atom:updated>2023-12-04T17:11:26.542Z</atom:updated>
            <content:encoded><![CDATA[<p>Every time you create a new class, you have to change the header manually to respect the code styling.</p><p>That’s annoying, your time is precious, you need to use it for more important tasks.</p><p>Today, we are going to see, how to customize your file header text in xcode.</p><ol><li>Create a new property list file and call it <strong><em>IDETemplateMacros.plist</em></strong><em>, then save it.</em></li><li>Open the <strong><em>IDETemplateMacros.plist</em></strong><em> file.</em></li><li><em>Add a new macro:</em></li></ol><ul><li><strong>key: FILEHEADER</strong></li><li>type <strong>string</strong></li><li>value:<strong> /* Copyright ___FULLUSERNAME___ and Contributors */</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*evJ2yT0MhxATs1nI3JqC5Q.png" /></figure><p>In my exemple I used <strong>FULLUSERNAME </strong>macro. Apple provide other macros. To see all of them, then<strong> </strong><a href="https://help.apple.com/xcode/mac/current/#/dev7fe737ce0"><strong>click here</strong></a>.</p><p>3. Finally, save your template to the appropriate location:</p><ul><li>If this template will be used with one project:</li></ul><p>*** If you are using a project, then saved it in:</p><blockquote><strong><em>&lt;YourProject&gt;.xcodeproj/xcshareddata/</em></strong></blockquote><blockquote><strong><em>Or</em></strong></blockquote><blockquote><strong><em>&lt;YourProject&gt;.xcodeproj/xcshareddata/</em></strong></blockquote><p>*** If you are using a workspace, then save it in:</p><blockquote><strong><em>&lt;YouWorkspaceName&gt;.xcworkspace/xcshareddata/</em></strong></blockquote><blockquote><strong>Or</strong></blockquote><blockquote><strong><em>&lt;YouWorkspaceName&gt;.xcworkspace/xcshareddata/</em></strong></blockquote><ul><li>If this template will be used with all your projects then put it in:</li></ul><blockquote><strong><em>~/Library/Developer/Xcode/UserData/</em></strong></blockquote><p><strong>Here we go !!!!!!</strong></p><p><strong>Now you can test it</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*gNmA-sTNR_ru4z6pWgnLPA.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3876c006548c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-with-me/how-to-customize-your-file-header-text-in-xcode-3876c006548c">How to customize your file header text in Xcode</a> was originally published in <a href="https://medium.com/code-with-me">Code with me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Singleton — Swift]]></title>
            <link>https://medium.com/code-with-me/singleton-swift-3a1820d8b0a?source=rss-f925904d66c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a1820d8b0a</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Mouna]]></dc:creator>
            <pubDate>Fri, 17 Jun 2022 22:35:28 GMT</pubDate>
            <atom:updated>2023-12-05T13:08:19.295Z</atom:updated>
            <content:encoded><![CDATA[<h3>Swift: Singleton</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iONzmnn_ZcBudQwC4bBN6g.jpeg" /></figure><p>Hello, in this blog, I will talk about an important design pattern “<strong>Singleton</strong>”.</p><h3>What is singleton ?</h3><p>Singleton is a design pattern used to create one shared and global instance that is initiates only one time.</p><h3>Where can be used ?</h3><p>Apple is already using singleton pattern. If you are using Apple’s framework, then you should used one of them. Here are somme examples:</p><pre>// Standard User Defaults<br>let standardUserDfaults = UserDefaults.standard<br><br>// Shared URL Session<br>let standardURLSession = URLSession.shared</pre><h3>How to implement it ?</h3><ul><li>Sample way:</li></ul><pre>class Singleton {<br>  static let shared = Singleton()<br>}</pre><ul><li>If you have some additional work to do when you initialize the shared instance, then you can use closure:</li></ul><pre>class Singleton {<br>  static let shared: Singleton = {<br>    let instance = Singleton()<br>    // Setup code return instance<br>    return instance<br>  }()<br>}</pre><p>Then you can call it like this:</p><pre>let shared = Singleton.shared</pre><p><strong>That’s it for Singleton.</strong></p><p><a href="https://developer.apple.com/documentation/swift/managing-a-shared-resource-using-a-singleton">https://developer.apple.com/documentation/swift/managing-a-shared-resource-using-a-singleton</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a1820d8b0a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/code-with-me/singleton-swift-3a1820d8b0a">Singleton — Swift</a> was originally published in <a href="https://medium.com/code-with-me">Code with me</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>