<?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[Dispatch Swift - Medium]]></title>
        <description><![CDATA[Dispatches from the world of Swift &amp; iOS development - Medium]]></description>
        <link>https://medium.com/dispatch-swift?source=rss----b015974e024---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Dispatch Swift - Medium</title>
            <link>https://medium.com/dispatch-swift?source=rss----b015974e024---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 15:22:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/dispatch-swift" 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 Protocol Series: Equatable]]></title>
            <link>https://medium.com/dispatch-swift/swift-protocol-series-equatable-7d46827deaf0?source=rss----b015974e024---4</link>
            <guid isPermaLink="false">https://medium.com/p/7d46827deaf0</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Arvindh Sukumar]]></dc:creator>
            <pubDate>Sun, 17 Apr 2016 13:45:49 GMT</pubDate>
            <atom:updated>2016-04-18T15:22:12.164Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Swift, as a highly protocol-oriented programming language, is chock-a-block with a multitude of protocols in its standard library. In this series, I hope to discover &amp; learn more about some of them.</em></p><h4>The Equatable Protocol</h4><p>Any two instances of a type that conforms to Equatable can be checked against each other to see if they’re equal in <em>value</em>.</p><p>If your custom type adopts this protocol, it is given the opportunity to specify what exactly this equality check is. Note that, by default, Swift structs &amp; classes are <em>not </em>equatable.</p><p>The way you go about doing this, is using the == operator function:</p><pre>func ==(lhs: Self, rhs: Self) -&gt; Bool</pre><p>Consider the example of an online bookmark. There might be multiple links online with the same title, but two links can be considered equal only if they point to the same URL.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7647a15e152c482d306bb5131af3eee6/href">https://medium.com/media/7647a15e152c482d306bb5131af3eee6/href</a></iframe><p>Inequality is automatically inferred from the return value of this function, and therefore, there is no need to implement !=. The two objects are simply inequal if the return value of == is false.</p><h4>Defining Equality</h4><p>It’s great that you can specify when exactly two instances are equal, but that doesn’t mean you can run away with your own implementation. Equality has to behave the way we would expect it to. To this end, the following properties should be met (Apple mentions this in the documentation for Equatable):</p><pre>1. x == x should be `true`.</pre><pre>Equality should be _reflexive_. Given a value &#39;x&#39;, if it is compared against itself, the value should always be true.</pre><pre>2. `x == y` implies `y == x`</pre><pre>Equality should be _symmetric_. Irrespective of which value is being compared _against_ which value, the return value should always be the same.</pre><pre>3. `x == y` and `y == z` implies `x == z`</pre><pre>Equality should be _transitive_. Given 3 values x,y &amp; z, if x == y is true, and so is y == z, then x == z should also be true.</pre><p>It is also important to note that this protocol only concerns itself with value, and not reference equality i.e <em>identity </em>(using ===). While it <em>is </em>possible to check for identity equality, since it is not the recommended practice, Apple recommends that such checks be documented appropriately.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d46827deaf0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dispatch-swift/swift-protocol-series-equatable-7d46827deaf0">Swift Protocol Series: Equatable</a> was originally published in <a href="https://medium.com/dispatch-swift">Dispatch Swift</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Type Constraints for Generics in Swift]]></title>
            <link>https://medium.com/dispatch-swift/type-constraints-for-generics-in-swift-d6bf2f0dbbb2?source=rss----b015974e024---4</link>
            <guid isPermaLink="false">https://medium.com/p/d6bf2f0dbbb2</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[generics]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Arvindh Sukumar]]></dc:creator>
            <pubDate>Sat, 16 Apr 2016 15:35:49 GMT</pubDate>
            <atom:updated>2016-04-16T15:35:49.521Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the most powerful parts of Swift is its support for Generics. Using Generics, you can write code that is type-agnostic, meaning less code duplication.</p><p>But Generic code, as such, accepts any type. If you however want to constrain your code to accept only certain types, and that too only in certain conditions, what you need are Type Constraints.</p><p>Generics are made even more powerful and flexible by Type Constraints (and Where clauses). This article is my attempt at understanding where and how Type Constraints can be used, and the minutiae of their implementation. So here goes.</p><p>You can specify Type Constraints in the following cases:</p><ol><li>Implementations of Generic Types</li><li>Generic functions</li><li>Extensions of Generic Types, and</li><li>Extensions of Generic Protocols</li></ol><h4>Generic Types &amp; Functions</h4><p>Constraints specified during the implementation of a Generic type limit the possible type parameters that can be used when creating an instance of that type.</p><p>The syntax for Type Constraints in Generic types as well as functions is the same:</p><pre>&lt;T, U where T: SomeClass, T: SomeProtocol, U: AnotherClass&gt;</pre><p>The above specifies that given two type parameters T &amp; U, T should be a subclass of SomeClass as well as conform to SomeProtocol, and U should be a subclass of AnotherClass. The constraints that are therefore possible are:</p><ol><li>Class inheritance requirement, and</li><li>Protocol conformance requirement</li></ol><p>There is a third set of constraints that are possible — related to the protocol requirement’s associated type.</p><pre>//Assuming that `AssociatedType` is the associatedtype of SomeProtocol:</pre><pre>// Specify that the associated type is _derived_ from a specific class. Note the requirement of class - any other type cannot be used.<br>&lt;T where T: SomeProtocol, T.AssociatedType:SomeClass&gt;</pre><pre>// Specify that the associated type is a specific type (not necessarily a class).<br>&lt;T where T: SomeProtocol, T.AssociatedType == SomeType&gt;</pre><pre>// Specify that the associated types of two different types that conform to the same protocol, are of the same type<br>&lt;T, U where T: SomeProtocol, U:SomeProtocol, T.AssociatedType == U.AssociatedType&gt;</pre><p>This is better explained in some examples:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a45b12bf834895664ce582bca9f8c7d7/href">https://medium.com/media/a45b12bf834895664ce582bca9f8c7d7/href</a></iframe><h4><em>Shorthand for class inheritance and protocol conformance requirements:</em></h4><p>The above constraints can just be shortened as follows:</p><pre>&lt;T:SomeProtocol/Class, U:SomeProtocol/Class where ... &gt;</pre><p>But this only works when there is a single protocol conformance or class inheritance constraint. Other such constraints should still be mentioned as part of the Where clause.</p><h4>Extensions of Generic Types</h4><p>When you specify constraints while defining extensions for a Generic type, such extensions are only applied to instances of the type that satisfy those constraints.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1218f06afa75975db63325db0cc879fb/href">https://medium.com/media/1218f06afa75975db63325db0cc879fb/href</a></iframe><p>The basic requirement for such extensions is that the constraints should be satisfiable, given the original constraints in the implementation of the type. For example, this will not work:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2cd853166acbd7b9d6e63000e0f496b3/href">https://medium.com/media/2cd853166acbd7b9d6e63000e0f496b3/href</a></iframe><p>Also, extensions of generic types cannot have an inheritance clause — meaning, you cannot have a type conforming to a protocol via an extension while having constraints as well.</p><h4>Extensions of Generic Protocols</h4><p>Generic protocols that have <a href="https://dispatchswift.com/generic-protocols-in-swift-b47414e29bba#.o06jrnen8">associated types</a> can be extended with additional constraints using those types. Such extensions will be available to all types that conform to the protocol <em>and also conform to the associated type constraints</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0ba9d14a56f6310f8287e5c91eb244a/href">https://medium.com/media/b0ba9d14a56f6310f8287e5c91eb244a/href</a></iframe><p>Direct type parameter constraints aren’t available in this case. For instance, there is no way to outright specify that a protocol extension be available to, say, only subclasses of certain types. The extension availability is only <em>inferred</em> based on the associated type constraints.</p><h4>Conclusion</h4><p>As you can see, Type Constraints offer an additional layer of flexibility and type-safety over plain Generics. These are just some of the ways you can do this. Have I missed anything? Let me know!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6bf2f0dbbb2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dispatch-swift/type-constraints-for-generics-in-swift-d6bf2f0dbbb2">Type Constraints for Generics in Swift</a> was originally published in <a href="https://medium.com/dispatch-swift">Dispatch Swift</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generic Protocols in Swift]]></title>
            <link>https://medium.com/dispatch-swift/generic-protocols-in-swift-b47414e29bba?source=rss----b015974e024---4</link>
            <guid isPermaLink="false">https://medium.com/p/b47414e29bba</guid>
            <category><![CDATA[protocol]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Arvindh Sukumar]]></dc:creator>
            <pubDate>Thu, 14 Apr 2016 17:56:59 GMT</pubDate>
            <atom:updated>2016-04-14T17:56:58.964Z</atom:updated>
            <content:encoded><![CDATA[<p>A protocol in Swift is generic when it does not enforce types in (some or all of) its variables and functions, on types that conform to it. Different conforming types can then implement the protocol in ways that’re relevant or convenient for them.</p><p>There are two ways to make a protocol generic:</p><ol><li>By adding a Self Requirement</li><li>By using Associated Types</li></ol><h4>Protocols with Self requirement</h4><p>The type for function parameters can be marked as <em>Self</em>. When this is done, the type is automatically resolved to the type of the conforming object. For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce72af6602508c5939b3f04a0c1c5ed2/href">https://medium.com/media/ce72af6602508c5939b3f04a0c1c5ed2/href</a></iframe><p>Protocols with self won’t work in the following cases though:</p><ul><li>Properties of type Self aren’t allowed. (<em>I’m unable to find any documentation for this though — this just doesn&#39;t compile, when I tried. But when you think of it, the use-case for this is pretty limited — how often do you have one type owning an instance of the same type?)</em></li><li>if Self is the return type of a function. For example:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6267cc1c954eb9ddd220089da2f4f08f/href">https://medium.com/media/6267cc1c954eb9ddd220089da2f4f08f/href</a></iframe><h4>Associated Types</h4><p>When using Self, there is only one generic type possible — the conforming type itself. Instead, it’s also possible to declare one or more <em>associatedtype</em>s<em> </em>inside the protocol. An associated type is a type that can be filled in later by the conforming type. Inside the protocol, it is just a declaration — It is upto the conforming type to define what that associatedtype is.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9d3c0d36a2c5141d919e78b36ef8411/href">https://medium.com/media/b9d3c0d36a2c5141d919e78b36ef8411/href</a></iframe><p>In the above example, the associatedtype can be instances of a String, an Enum, or an array of Strings! The best part is that it’s upto the conforming type to provide this implementation detail — and it can choose the one that’s the most appropriate.</p><h4>Conclusion</h4><p>Generic protocols offer a lot of flexibility in enabling similar functionality across varied types. In this age of Protocol-oriented Programming, they’re definitely wonderful tools to have in your toolbox.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b47414e29bba" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dispatch-swift/generic-protocols-in-swift-b47414e29bba">Generic Protocols in Swift</a> was originally published in <a href="https://medium.com/dispatch-swift">Dispatch Swift</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Render a Map as an Image using MapKit]]></title>
            <link>https://medium.com/dispatch-swift/render-a-map-as-an-image-using-mapkit-3102a5a3fa5?source=rss----b015974e024---4</link>
            <guid isPermaLink="false">https://medium.com/p/3102a5a3fa5</guid>
            <category><![CDATA[mapkit]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Arvindh Sukumar]]></dc:creator>
            <pubDate>Mon, 11 Apr 2016 18:02:32 GMT</pubDate>
            <atom:updated>2016-04-11T18:02:32.277Z</atom:updated>
            <content:encoded><![CDATA[<p>The MapKit framework allows you to create and embed maps in your app. But sometimes, embedding an entire map may be overkill — like if you want display multiple coordinates, as a list of maps in a UITableView. Or if you want the map to be non-interactive.</p><p>In such cases, it makes more sense to create a <strong>snapshot </strong>of a map, and use <em>that </em>in your app.</p><h4>Introducing MKSnapshotter</h4><p>MapKit provides you a MKSnapshotter class that you use for the specific purpose of rendering a map as an image.</p><p>All the configuration for the snapshotter is defined by MKSnapshotOptions. The configuration includes the region to render, as well as display options like showing buildings &amp; points of interest, image size etc.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbd8eebf1967c15a8676e7bc95a8bf6b/href">https://medium.com/media/cbd8eebf1967c15a8676e7bc95a8bf6b/href</a></iframe><p>To set the region, we need an <strong>MKCoordinateRegion</strong>. We make one using a set of lat-long coordinates for the centre, and the distance in meters for the breadth (lat) and width (long) of the region to be displayed. Note that you can use other convenience methods to create the MKCoordinateRegion, but this one is the easiest to construct, without needing any complex conversions.</p><p>Once the snapshotter is ready, creating the snapshot is a piece of cake. Just use the <em>startWithCompletionHandler </em>function — it will asynchronously generate the snapshot for you.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6cc09f8812b0bee79bc2f02dfa2d440e/href">https://medium.com/media/6cc09f8812b0bee79bc2f02dfa2d440e/href</a></iframe><p>You can then cache this image somewhere, so that you can display it as needed, without having to (asynchronously) generate it all the time.</p><p>The above code generates the following image, BTW:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*9OM1gtqUufYxaFo925xG7g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3102a5a3fa5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dispatch-swift/render-a-map-as-an-image-using-mapkit-3102a5a3fa5">Render a Map as an Image using MapKit</a> was originally published in <a href="https://medium.com/dispatch-swift">Dispatch Swift</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advantages & Disadvantages of Structs in Swift]]></title>
            <link>https://medium.com/dispatch-swift/advantages-disadvantages-of-structs-in-swift-4f4c67d9aa67?source=rss----b015974e024---4</link>
            <guid isPermaLink="false">https://medium.com/p/4f4c67d9aa67</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Arvindh Sukumar]]></dc:creator>
            <pubDate>Sun, 10 Apr 2016 14:48:31 GMT</pubDate>
            <atom:updated>2016-04-10T14:48:31.104Z</atom:updated>
            <content:encoded><![CDATA[<p>When designing the models and data structure for your app, you would probably be deciding between <strong>Structs</strong> and <strong>Classes</strong>.</p><p>If you’re coming from a different programming language, it’s easy to settle into a pattern of using classes throughout your app.</p><p>However, structs in Swift are highly significant — they have been given tremendous importance throughout the Swift Standard Library itself. You too, should keep them in mind for your own apps. The following set of pros and cons should help you make a decision in this regard.</p><h4>Advantages:</h4><ol><li>Structs are marginally faster at runtime than classes, due to optimisations done by the compiler.</li><li>You can enforce full immutability. If you declare a struct instance as <strong>let</strong>, you will not be able to change its properties. Whereas, with classes, immutability is only with respect to the reference held by the constant — you’ll still be able to change its properties.</li><li>Since structs are value types, each instance is a unique copy of data. Because of this, when using structs in a multi-threaded environment, each thread could have its own copy of the data, and chances are low of one thread changing data out under you in a different thread. <em>Of course, if your instance of the struct is mutable, or if you mix reference types in your struct (see below), the chances of this happening are higher — but if you’re using a class, even the little safety you’d get is lost.</em></li></ol><h4>Disadvantages</h4><ol><li>Structs do not support inheritance. Depending on how you look at it, this may not be a bad thing, but this is certainly something to keep in mind while designing your models.</li><li>They cannot conform to a <em>class </em>protocol (duh), such as NSObjectProtocol. This seems like an obvious thing to say, but you may never know at what point you need to start complying to a protocol — and a lot of Foundation protocols (for example) have been defined as class protocols.</li><li>You lose identity (===) comparison. Identity comparison is useful in cases like event handling, when you want to check which object emitted the event. With classes, you can do, for example <em>if (sender === instance).</em></li><li>Structs are cool when used as pure value types, i.e a single struct made up of other value types — structs or enums. But when you bring reference semantics into the equation, things can get messy. The thing is, while a struct is copied by value on assignment, any property that is a reference type is copied by — you guessed it — reference. Even if it is marked as <strong>let</strong>, if the reference type is mutated elsewhere, the struct is also affected. For example:</li></ol><pre>struct Person {</pre><pre>    var name: String</pre><pre>    var job: Job</pre><pre>}</pre><pre>class Job {</pre><pre>    var title: String!</pre><pre>}</pre><pre>var job = Job()</pre><pre>job.title = “Accountant”<br></pre><pre>let person1 = Person(name: “John”, job: job)</pre><pre>let person2 = person1 // Hey, let&#39;s clone John!<br></pre><pre>person1.job.title = “Software Engineer”</pre><pre>print(person1.job.title) // Software Engineer</pre><pre>print(person2.job.title) // Software Engineer (!)</pre><p>These are just a few things you can keep in mind. Anything you think I’ve missed out? Let me know!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f4c67d9aa67" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dispatch-swift/advantages-disadvantages-of-structs-in-swift-4f4c67d9aa67">Advantages &amp; Disadvantages of Structs in Swift</a> was originally published in <a href="https://medium.com/dispatch-swift">Dispatch Swift</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Synchronise Multiple Async Tasks With Dispatch Groups]]></title>
            <link>https://medium.com/dispatch-swift/introduction-to-dispatch-group-a5cf9d61ff4f?source=rss----b015974e024---4</link>
            <guid isPermaLink="false">https://medium.com/p/a5cf9d61ff4f</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Arvindh Sukumar]]></dc:creator>
            <pubDate>Thu, 07 Apr 2016 15:41:59 GMT</pubDate>
            <atom:updated>2016-04-08T05:50:22.626Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>dispatch_group</strong><em> </em>is a part of Apple’s Grand Central Dispatch (GCD) set of APIs that allows you to coalesce and synchronise the results of multiple asynchronous functions into a single point of execution.</p><p>With dispatch_groups, a thread is blocked until all tasks associated with that group are finished. And once they are finished, normal execution resumes, and you can be safe in the knowledge that all your asynchronous code has finished running.</p><p>Suppose you have multiple async network calls, that are not dependent on each other, but you still need to wait for all the calls to complete before proceeding. A naïve implementation of this (that I’m guilty of 😅) would look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44ca6356ac0b847e3fb45eb512b84d43/href">https://medium.com/media/44ca6356ac0b847e3fb45eb512b84d43/href</a></iframe><p>Or perhaps you’d chain one function to another, in nested callback hell. You’d lose some of the asynchronous nature of your code in that case.</p><p>With dispatch_groups though, the implementation becomes much cleaner:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a856c5f1d69ff60118b915f236bd3752/href">https://medium.com/media/a856c5f1d69ff60118b915f236bd3752/href</a></iframe><p>Notice how there are no longer multiple unnecessary calls to a <strong>checkResults()</strong> function 😛</p><h4>How it works</h4><p>Before calling the different async functions, a <strong>dispatch_queue</strong> is first created. This could be an instance variable in your class, as above.</p><p>Next, in each function, before the execution becomes concurrent, a call to <strong>dispatch_group_enter</strong> is made. This tells GCD that a task was added.</p><p>When the async call returns with results, <strong>dispatch_group_leave</strong> is called. This tells GCD that a task was completed.</p><p>When all the <strong>entries</strong> are balanced out by the same number of <strong>leaves</strong>,<strong> </strong>the group is treated as finished, and the thread proceeds to the next step. <em>Note that it is important that this balancing occurs — otherwise, the group will never finish.</em></p><p>Once the group is finished, there are two ways of handling it:</p><ul><li>Using <strong>dispatch_group_wait</strong>: The thread pauses execution at this stage, until all tasks are complete. The next statement will only be executed after either that, or the timeout specified - whichever is earlier. This is the approach in <strong>startRequests()</strong>.</li><li>Using a notification block: This provides you the opportunity of executing some code, on a specified thread, after all tasks are complete. This is the approach in <strong>alsoStartRequests().</strong></li></ul><p>And that’s all there is to it — easy synchronisation of async code, with just 3–4 simple APIs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5cf9d61ff4f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dispatch-swift/introduction-to-dispatch-group-a5cf9d61ff4f">Synchronise Multiple Async Tasks With Dispatch Groups</a> was originally published in <a href="https://medium.com/dispatch-swift">Dispatch Swift</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running RunLoop-Based Async Code in Swift Playgrounds]]></title>
            <link>https://medium.com/dispatch-swift/running-runloop-based-async-code-in-swift-playgrounds-112cac8d1648?source=rss----b015974e024---4</link>
            <guid isPermaLink="false">https://medium.com/p/112cac8d1648</guid>
            <category><![CDATA[playground]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Arvindh Sukumar]]></dc:creator>
            <pubDate>Wed, 30 Mar 2016 10:33:41 GMT</pubDate>
            <atom:updated>2016-03-30T10:33:41.173Z</atom:updated>
            <content:encoded><![CDATA[<p>By default, Swift Playgrounds do not execute (asynchronous) code that depends on the RunLoop for callbacks or completion.</p><p>This includes, for example ,<em> NSURLConnection/Session</em> requests, and <em>NSTimer</em> actions.</p><p>This is because, the code in the Playground is executed, and the process is terminated — the completion operations / callbacks are simply not executed.</p><p>To enable this, there are two options</p><h4>Use the XCPlayground API</h4><pre>XCPlaygroundPage.currentPage.needsIndefiniteExecution = true </pre><pre>// Your Code</pre><p>This creates a 30-second window for the async code to execute and finish, after which it’ll time-out. This duration can be customised using the timeline view (at the bottom of the playground). After the code is executed, you can call:</p><pre>XCPlaygroundPage.currentPage.finishExecution()</pre><h4>Run an NSRunLoop yourself.</h4><pre>NSRunLoop.currentRunLoop().runUntilDate(NSDate().dateByAddingTimeInterval(30)) </pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=112cac8d1648" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dispatch-swift/running-runloop-based-async-code-in-swift-playgrounds-112cac8d1648">Running RunLoop-Based Async Code in Swift Playgrounds</a> was originally published in <a href="https://medium.com/dispatch-swift">Dispatch Swift</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>