<?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 David Rico on Medium]]></title>
        <description><![CDATA[Stories by David Rico on Medium]]></description>
        <link>https://medium.com/@Ricowere?source=rss-9bd7e4531c1e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8huVxovUunQVw458UB-yjw.jpeg</url>
            <title>Stories by David Rico on Medium</title>
            <link>https://medium.com/@Ricowere?source=rss-9bd7e4531c1e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 18:17:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Ricowere/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[DateInterval — New in Foundation framework]]></title>
            <link>https://medium.com/@Ricowere/dateinterval-new-in-foundation-framework-315f1d970bb7?source=rss-9bd7e4531c1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/315f1d970bb7</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[objective-c]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[David Rico]]></dc:creator>
            <pubDate>Sun, 12 Feb 2017 16:58:24 GMT</pubDate>
            <atom:updated>2017-02-12T17:10:11.352Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9JhB7mo_YpbHHwi4yPPXag.png" /><figcaption>API availability</figcaption></figure><p>A new helpful struct (NSObject class for objc) has been added in the recent version of Foundation framework to make our day by day a bit easier. I think most of us in our projects have had to deal with Dates sometimes. Working with Dates is delicate, especially if we need to deal with date operations or timezones. The newly introduced DateInterval struct will help us to deal easily with date intervals.</p><p>In this post I’ll do a brief introduction of the main DateInterval features, here I go!</p><h4>Initialization</h4><p>DateInterval will provide us with three available initializers;</p><blockquote>public init()</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8YQMfSwGU-Z3joXKJGpbhQ.png" /><figcaption>Default Initializer.</figcaption></figure><blockquote>public init(start: Date, end: Date)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e3ZcxYQCjWnQgu6yP79-3A.png" /><figcaption>Providing a start and end date.</figcaption></figure><blockquote>public init(start: Date, duration: TimeInterval)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NXSluVgCw7AB88np7nDxCw.png" /><figcaption>Providing a start date and the interval’s duration</figcaption></figure><h4>Operations over a DateInterval</h4><p>The interesting part comes with the operations we could perform with DateIntervals such a intersecting two given intervals, checking if an interval is contained in another or sorting an intervals collection.</p><blockquote>public func contains(_ date: Date) -&gt; Bool</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zzu0YJSBM0_AZ5ZWhaGcMQ.png" /><figcaption>contains?</figcaption></figure><blockquote>public func intersects(_ dateInterval: DateInterval) -&gt; Bool</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pF6omQBdfBDz07uwqrtAaw.png" /><figcaption>intersects?</figcaption></figure><blockquote>public func intersection(with dateInterval: DateInterval) -&gt; DateInterval?</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HdlD_DhbB8Y-uvg70Xw6mQ.png" /><figcaption>New DateInterval intersection.</figcaption></figure><h4>Sorting</h4><p>This part is trickier and I recommend to take a look to the documentation to understand how the comparison is performed. Briefly resumed and quoting the apple documentation; <em>“the comparison priorities ordering by start date. If the start dates are equal, then it will order by duration.”</em></p><p>Therefore, given the unsorted collection below;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yAWodMPwPGEwT9v51oElkQ.png" /><figcaption>Unsorted DateInterval colletion.</figcaption></figure><p>We could sort it following the common approaches;</p><blockquote>Sort ascending</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eIFiCXqxe2pmgxmkPNyLZA.png" /><figcaption>Sorted ascending by startDate</figcaption></figure><blockquote>Sort descending</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XPI2bSeIIds9UC2uuHt_Ng.png" /><figcaption>Sorted descending by startDate</figcaption></figure><p>I hope you found useful this introduction, you can experiment it with a <a href="https://github.com/Ricowere/DateInterval">playground</a> I’ve created. Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=315f1d970bb7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Strongly typed Notifications with Swift. Lean approach.]]></title>
            <link>https://medium.com/@Ricowere/strongly-typed-notifications-lean-approach-58cb20cebb29?source=rss-9bd7e4531c1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/58cb20cebb29</guid>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[David Rico]]></dc:creator>
            <pubDate>Tue, 17 Jan 2017 17:22:23 GMT</pubDate>
            <atom:updated>2017-01-28T14:06:43.375Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ca69vjmxQIdkOfW-O6hZaA.png" /></figure><p>Notifications. Aka NSNotifications. Who haven’t used it sometimes? Who haven’t got a “bad” or “weak” developer feeling by using it sometimes? :)</p><p>The truth is as iOS Engineers either liking them or not, we have to deal with them and the safest way we deal with it, the more robust solution we will achieve.</p><p>I’m gonna propose you a lean approach of how to solve this problem in a testable way. And more important than that, without writing no more than the needed lines of code.</p><blockquote>Remember that we are humans, the more lines we write (even tests) the more bugs we introduce in the system.</blockquote><p>Let’s start!</p><p>We will have three main parts in our approach. An <em>Event</em>, a <em>Controller</em> for that <em>Event, </em>and also an<em> Observer </em>of the Event. I bet the description above is self-explicative.</p><h4>Event</h4><p>The event represents the minimum unit of relevant information for any element interested on listen it.</p><p>It has the responsibility of adapt the Notification is received by implementing the NotificationAdapter protocol declared for that purpose.</p><p>Also I provided a default implementation for letting an Event works with a minimum set of requirements.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bcf324da0318e5d7981db929dc466e4/href">https://medium.com/media/7bcf324da0318e5d7981db929dc466e4/href</a></iframe><h4>Controller</h4><p>The controller acts as an entry-point for any element that wants to listen or publish an Event. Also it’s the responsible piece for giving the strongly typed environment that we are eager to achieve! It has two main methods for that; <em>publish</em> and <em>listen (Self-explicative I bet as well)</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8149b666eed162d605d123d6a5e9147e/href">https://medium.com/media/8149b666eed162d605d123d6a5e9147e/href</a></iframe><h4>Observer</h4><p>A proxy object that is responsible of listening and terminate the listening when it’s released. Under the hood how I’m proceeding is basically wrapping up the <em>NotificationCenter</em> under the <em>Controller</em>, therefore I’ll be able to test it!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c4dab96945e61b7932bed73a6382840/href">https://medium.com/media/6c4dab96945e61b7932bed73a6382840/href</a></iframe><h4>Practical Use</h4><p>In the example below we can see how we achieve a sweet and simple interface with only a few lines of code!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01599bdd3a791301959c5eff5950b5e3/href">https://medium.com/media/01599bdd3a791301959c5eff5950b5e3/href</a></iframe><p>In the example above I’ve used a basic implementation of an Event. You could take a look in the <a href="https://github.com/Ricowere/EventsController">playground</a> where I’m using a bit more complex event.</p><p>Github example <a href="https://github.com/Ricowere/EventsController">here</a>.</p><p>Happy reading! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58cb20cebb29" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[User engagement on iOS with Swift — Part 1]]></title>
            <link>https://medium.com/busuu-tech/user-engagement-on-ios-with-swift-part-1-642d7e536709?source=rss-9bd7e4531c1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/642d7e536709</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[deep-linking]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[David Rico]]></dc:creator>
            <pubDate>Thu, 23 Jun 2016 12:01:04 GMT</pubDate>
            <atom:updated>2016-06-23T14:22:38.319Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*CsRAfqb78Loswkrz9TqTug.png" /><figcaption>Force touch</figcaption></figure><p><em>This is part 1 of a three part series on increasing engagement with iOS users to give your users a tightly integrated and clean experience. We’ll cover deep links, Push Notifications, Universal Links, Spotlight, and Handoff, and how they all fit together to provide a seamless experience for your users.</em></p><h4>Deep links. A clean way.</h4><p>As the complexity of an application evolves, we accrue technical debt in any number of areas, including deep links. Usually when it comes to deep links, the kind of technical debt we would expect to run in to would be continually adding new deep links, and duplicating the functionality of deep links.</p><p>We can use deep links for lots of different entry points into our application, for example opening the app from push notifications, a universal link or a spotlight search. We want to make sure that we build the architecture of our deep links in such a way that we mitigate the potential issues, and in such a way that it can be used for all the different entry points in a uniform, reusable and testable way.</p><p>Below we’ll tackle this problem in a scalable, testable and robust way following (as much as possible) clean principles and design patterns.</p><p>Let’s suppose our app has to be able to open an user profile from a URL given in such a different ways.</p><blockquote>my-app://profile?id=ID_USER</blockquote><blockquote>www.my-server.com/profile/ID_USER</blockquote><blockquote>subdomain.my-server.com/colleague/ID_USER</blockquote><blockquote>www.my-server.com/from/twitter/user/ID_USER</blockquote><p>They’re heterogeneous URLs but their target will be the exactly the same, open a profile page in our app from a given user id.</p><p>Let’s start by analysing which responsibilities / roles our system has:</p><ul><li>Register all the URLs the app is able to handle - we have to keep a track of which URLs our system handle.</li><li>Parse the URL to extract all the information needed like identifying the URL and collect all the parameters it has.</li><li>Evaluate if the URL provided is valid for our app.</li><li>Execute the associated action for the given URL.</li></ul><h4>Architecture</h4><p>Taking this analysis, we can generate the beginnings of how we would build our app to generically handle all types of links. Let’s start with a high level model made up of interfaces, understand how this applies to the problem, and then we’ll use this model to generate how we would implement linking.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pol27P0E18t82HDAz7gp0Q.jpeg" /></figure><ul><li><strong>LinkController — </strong>This is the interface with the routing role. It will be the entry point to the system.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18b587fbdcc892cd0849746d15c95274/href">https://medium.com/media/18b587fbdcc892cd0849746d15c95274/href</a></iframe><ul><li><strong>LinkActionFactory — </strong>This is a factory with all the actions needed from the LinksController.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0630d37f6c9119f1f01424f83766a4c1/href">https://medium.com/media/0630d37f6c9119f1f01424f83766a4c1/href</a></iframe><ul><li><strong>LinkAction — </strong>It will be the atomic unit in the system. An action contains two main parts: the action type and the URL map.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fda309af079cc7c08db2cb668870fed7/href">https://medium.com/media/fda309af079cc7c08db2cb668870fed7/href</a></iframe><p>Note that we modeled all the domain with interfaces (protocols) to be able to have scalable code and having loose coupling between classes. This kind of approach should be familiar to you with the newly introduced <a href="https://developer.apple.com/videos/play/wwdc2015/408/"><em>“Protocol oriented programming”</em> in Swift</a>. Also known as <a href="https://en.wikipedia.org/wiki/Composition_over_inheritance">Composition over Inheritance</a> and <a href="https://en.wikipedia.org/wiki/Design_by_contract">DbC (design by contract)</a>, plus other concepts related with Computer Science and Software engineering.</p><h4>Implementation</h4><p>Let’s create some concrete classes that will implement the protocols needed for all the interfaces we have declared.</p><ul><li><strong>ThirdPartyLinkController : LinksController </strong>To save in development costs and time (your boss will appreciate it especially if you are in an startup!) <a href="https://github.com/joeldev/JLRoutes">we can use a pretty good library</a> that will help us to do part of the work. Our ThirdPartyLinkController implements the interface and uses the external library to do the heavy lifting, however if in the future we need to remove or replace that third party library our system will be agnostic of that change. (D of SOLID principles)</li><li><strong>OpenUserProfileLinkAction : LinkAction </strong>This will be the concrete class to open a user profile. In our case will be necessary receive the USER_ID and a sourceViewController to open it from.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd385469890103c80c9f1256710b1246/href">https://medium.com/media/bd385469890103c80c9f1256710b1246/href</a></iframe><ul><li><strong>ShowAnotherTabLinkAction : LinkAction</strong> As another example, this will be an action to open a tab given by parameter.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c255b8c2c3b78c55cc5ce9820c3cb526/href">https://medium.com/media/c255b8c2c3b78c55cc5ce9820c3cb526/href</a></iframe><p>Having all the concrete classes created, lets take a look at how the diagram ends up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WdVSWLNw7akvp5r-iKcK0g.jpeg" /></figure><p>So cool! So neat! 😄</p><h4>Show me the code!</h4><ul><li>Check it out on <a href="https://github.com/Ricowere/LinksController">Github</a>.</li></ul><p>In the next chapters you’ll see how can we use this design with all the external events. Stay tuned!</p><blockquote>Chapter 2: Multiple entry points, same responsibility.</blockquote><blockquote>Chapter 3: Testing the link actions.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=642d7e536709" width="1" height="1" alt=""><hr><p><a href="https://medium.com/busuu-tech/user-engagement-on-ios-with-swift-part-1-642d7e536709">User engagement on iOS with Swift — Part 1</a> was originally published in <a href="https://medium.com/busuu-tech">Busuu Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>