<?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 Rui Costa on Medium]]></title>
        <description><![CDATA[Stories by Rui Costa on Medium]]></description>
        <link>https://medium.com/@ruipfcosta?source=rss-bb4d09a25fe------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*l1Y31jufpdu-thkO1P48RA.jpeg</url>
            <title>Stories by Rui Costa on Medium</title>
            <link>https://medium.com/@ruipfcosta?source=rss-bb4d09a25fe------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 05:25:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ruipfcosta/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, MVVM and Combine]]></title>
            <link>https://medium.com/yoyo-engineering/swift-mvvm-and-combine-2c4825227c60?source=rss-bb4d09a25fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c4825227c60</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[combine]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[mvvm]]></category>
            <dc:creator><![CDATA[Rui Costa]]></dc:creator>
            <pubDate>Fri, 12 Jul 2019 13:30:45 GMT</pubDate>
            <atom:updated>2019-07-12T14:26:35.800Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the most exciting announcements from this year’s WWDC is the new <a href="https://developer.apple.com/documentation/combine">Combine framework</a>. Combine provides a declarative Swift API for processing values over time, similar to other frameworks such as RxSwift or ReactiveSwift. The announcement means <a href="https://en.wikipedia.org/wiki/Functional_reactive_programming">Functional Reactive Programming</a> (FRP) now becomes a first-party paradigm in the iOS world!</p><p>Although some types have different names in RxSwift and Combine, the main principles behind them are the same and should be very easy to transfer knowledge between both frameworks. At Yoyo Wallet we started using RxSwift/FRP mainly to allow different parts of the app to observe and react to data updates, but with time, and after adopting MVVM as our architectural pattern, we also started using RxSwift to set up bindings between view models and view controllers, control state changes and trigger actions.</p><p>In this article I’ll be showing a technique to structure view models and control the flow of data using Combine. This approach is essentially the same we use at Yoyo, the difference being that we use RxSwift instead of Combine. For simplicity, I’ll be focusing on UIKit (<a href="https://developer.apple.com/documentation/swiftui">sorry…</a> 😀)! I know Combine + UIKit might be an unlikely combination since SwiftUI is also available starting from iOS 13, so in reality this is an exercise to replace RxSwift with Combine in order to get familiar with it.</p><h3>View model</h3><p>A view model is a pure Swift representation of a view, holding all its business logic. By “view” I mean not just subclasses of UIView but also, and most importantly, UIViewController subclasses. To demonstrate this, let’s pretend we are building a new screen for our app to display the details of a product and allow the user to purchase it. The screen will have a couple of labels for the product’s title and description, and a button which, when tapped, triggers an API call to the backend to make that purchase. If something goes wrong with that request, a third label will show the error message to the user.</p><p>At this point we already have enough information to start building our view model:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09fd9604da3db90b3ceae37364ea6279/href">https://medium.com/media/09fd9604da3db90b3ceae37364ea6279/href</a></iframe><p>As you can see, this was almost a direct translation from English to Swift! For each property we want to control on the view there is an associated property on the view model. Each view model property is defined as CurrentValueSubject, one of the Subject types included in Combine (in RxSwift we would use a BehaviorRelay). But why use CurrentValueSubject and not plain Swift types such as String and Bool? The answer is simple, one of the key aspects of MVVM is the usage of data bindings to connect the view model to the view. CurrentValueSubject will allow us to set and observe its value over time, ensuring the view controller&#39;s IBOutlets are always updated accordingly.</p><h3>State</h3><p>I also mentioned that the error label is only visible when the API call fails. We can immediately identify two states for our screen: an initial state in which the user is presented with the details of a product, and an error state for when things go wrong when making the purchase. An enum feels appropriate to represent these two cases:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/909966d6e11d9eaab284cbc749fc9a26/href">https://medium.com/media/909966d6e11d9eaab284cbc749fc9a26/href</a></iframe><p>Now let’s define a function to process the state. The different view model properties will be set accordingly depending on the current state:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1943c1b76ad5f0e2f0353e3afb428efa/href">https://medium.com/media/1943c1b76ad5f0e2f0353e3afb428efa/href</a></iframe><p>In order to glue everything together we just need to define a state property on the view model (again using CurrentValueSubject) and observe any changes to its value using thesinkfunction (subscribe if we were using RxSwift). Every time the value changes, all we need to do is to call the processState function created above which will then set the properties based on the current state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b3792a56c238f4b4c57f8e2ca9e195a/href">https://medium.com/media/2b3792a56c238f4b4c57f8e2ca9e195a/href</a></iframe><p>Later on we’ll see how the view model properties will be connected to the view controller’s IBOutlets.</p><h3>Actions</h3><p>It makes sense for the view model to be the one who handles the purchase of the product. This means the view will need a way to communicate that intention to the view model. We can start by defining an Action enum containing the possible actions supported by the view model, similar to the State enum we created earlier:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04668c3fc9e33dc41ba6967d1fc0c89d/href">https://medium.com/media/04668c3fc9e33dc41ba6967d1fc0c89d/href</a></iframe><p>And we can use the same approach as above to handle the actions:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb42ed39275d7ac578447f42140e45d5/href">https://medium.com/media/fb42ed39275d7ac578447f42140e45d5/href</a></iframe><p>This time however we’re using another type of Subject, a PassthroughSubject. (in RxSwift we would use a PublishSubject). The difference to the CurrentValueSubject used for the state is that, as the name suggests, its current value is not stored, it can only be observed. This is fine, because we just need to be informed every time an action is triggered and react to that. However, for the state we may need to access its current value at some point, so I prefer to use a CurrentValueSubject for it, although a PassthroughSubject would also be valid.</p><h3>View</h3><p>After all the progress we’ve made so far, the view will be incredibly simple to implement! Let’s start by defining the IBOutlets we need and create the view model:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/123b152b4a10c1eca8216bb9720fc78a/href">https://medium.com/media/123b152b4a10c1eca8216bb9720fc78a/href</a></iframe><p>For the sake of this example let’s just assume the view model is created inside the view controller. In practice there are better ways to do this (I quite like the <a href="https://benoitpasquier.com/coordinator-pattern-swift/">coordinator pattern</a>).</p><p>Nothing exciting so far, but that’s about to change! We already know our view model contains all the relevant properties for this view, and contains all the logic to determine how those properties should be set on each state. This means we just need to connect those properties to the view’s IBOutlets using the assign function (in RxSwift we would be looking at bind):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5eee9338696e5fe97abd4c886ad44ce/href">https://medium.com/media/b5eee9338696e5fe97abd4c886ad44ce/href</a></iframe><p>We’ll need to hold a reference to the Cancelable objects returned by assign, otherwise the subscription will get terminated. The easiest way to do it is to just put all of them inside an array, but we could have also kept individual references to each Cancelable if we wanted.</p><p>Finally, we just need to connect the tap gesture on the purchase button to the respective action on the view model:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9226aadb3e6ec221d9ba2d8030f5b932/href">https://medium.com/media/9226aadb3e6ec221d9ba2d8030f5b932/href</a></iframe><h3>Conclusion</h3><p>It’s easy to design an MVVM architecture for our apps based on the new Combine framework. Here’s a quick summary of what we’ve implemented:</p><ul><li>Every property we want to control on the view is matched by a property on the view model;</li><li>The view model defines enums and properties for both state and actions;</li><li>The view model observes state changes and sets its properties accordingly;</li><li>The view model reacts to any actions triggered by the view;</li><li>The view controller connects the view model properties to its IBOutlets.</li></ul><p>And finally, it’s great to see Apple coming up with their own FRP framework avoiding the need to link other third-party dependencies to our apps!</p><p>You can find a sample project in this <a href="https://github.com/ruipfcosta/MVVM-Combine-Example/tree/master">Github repository</a>.</p><p>Thanks for reading! 🎉</p><p>Thanks to <a href="https://medium.com/u/6ac5ee90e639">Tom Morrell</a> for reviewing the text! If you have any thoughts or comments you can find me on Twitter <a href="https://twitter.com/ruipfcosta">@ruipfcosta</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c4825227c60" width="1" height="1" alt=""><hr><p><a href="https://medium.com/yoyo-engineering/swift-mvvm-and-combine-2c4825227c60">Swift, MVVM and Combine</a> was originally published in <a href="https://medium.com/yoyo-engineering">Yoyo Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrating Yoyo Wallet to Swift 3]]></title>
            <link>https://medium.com/yoyo-engineering/migrating-yoyo-wallet-to-swift-3-f9863ddccff1?source=rss-bb4d09a25fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9863ddccff1</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Rui Costa]]></dc:creator>
            <pubDate>Wed, 23 Nov 2016 10:32:20 GMT</pubDate>
            <atom:updated>2016-11-23T10:55:10.135Z</atom:updated>
            <content:encoded><![CDATA[<p>A few days ago I came across <a href="https://medium.com/@yammereng/yammer-ios-app-ported-to-swift-3-e3496525add1#.t1wrynq5k">this article</a> by Yammer Engineering describing their process of migrating their codebase to Swift 3. I found it particularly interesting given we’ve been through the exact same process recently at Yoyo Wallet.</p><p>Our iOS codebase consists of two main projects: the Yoyo Wallet app containing mainly the UI side of things, and the Yoyo SDK which handles the requests to our platform, caching and persistence. Considering the two projects’ code, including unit tests and UI tests, we are roughly talking about 21K Swift LOC on the app project, plus 8k Swift LOC on the SDK project. Apart from a couple of customised Objective-C libraries, Swift code represents &gt;92% of our entire codebase!</p><p>In terms of external dependencies, our dependency manager of choice is <a href="https://github.com/Carthage/Carthage">Carthage</a>. Among others, our stack includes libraries like Realm, RxSwift, Alamofire and Moya.</p><h3>Reasons to migrate</h3><p>It’s clear that if we didn’t migrate now, we would have to do it at some point in the future — in the meantime we would keep adding more and more features until we found a suitable time to migrate. The worst-case scenario would be watching most of our dependencies evolving in time, new Swift versions coming out, new Xcode versions being released, and we would still be stuck with Swift 2.2.</p><p>The other reason to migrate was opportunity: we had just completed some development related to our recent <a href="https://www.nus.org.uk/en/lifestyle/what-has-nus-ever-done-for-students/">partnership with the National Union of Students</a> and were in the process of diving straight into another really important piece of work for us related to our <a href="https://www.linkedin.com/pulse/caff%C3%A8-nero-selects-yoyo-wallet-its-mobile-loyalty-payment-rolph">partnership with Caffè Nero ☕</a> . For us, it just felt logical to migrate to Swift 3 at this point in time otherwise there would be the risk of not having such a good opportunity to migrate any time soon. And again, the amount of technical debt accumulated until then was 😩.</p><h3>Swift 2.3 or Swift 3?</h3><p>We felt this question was relatively straightforward, although it could be tempting to migrate to Swift 2.3, we felt the migration wouldn’t be complete — if we were going to spend time and effort migrating, why not go directly to Swift 3 instead? Another strong point in favour of Swift 3 is the fact that Xcode 8.2 will be the last version to support Swift 2.3. According to the release notes, “<em>Xcode 8.2 is the last release that will support Swift 2.3. Please migrate your projects to Swift 2.3…”. </em>The decision was to go for Swift 3.</p><h3>The process</h3><p>After deciding to go ahead with the migration to Swift 3, we agreed that the best way to tackle it would be to stop all our iOS development work and pair for this migration task (Yoyo Wallet currently has two iOS developers). Because the migration would have to be done all at once (you can’t really have a mixed codebase with different Swift versions) we would always be blocking the other’s work, so the most logical thing to do was to work on it together and just get it done.</p><p>As I mentioned earlier, we have an SDK project where the requests to our platform and persistence are handled, which is a dependency of the main Yoyo Wallet app project. Because of this, we had to start the migration on the SDK project initially. This was also a good thing because it allowed us to start on a smaller section of the codebase and define a process that could be applied to the Yoyo Wallet app project.</p><p>The first thing we did after upgrading Xcode (and taking a long and deep breath) was to update our dependencies. Fortunately all of our Swift dependencies are well maintained and had already added support for Swift 3, so this process was surprisingly straightforward. The only problem here was that because some of the dependencies hadn’t been updated in a while, we also had to deal with some API changes and rework how certain parts of our code were using those dependencies.</p><p>After this (and taking another long and deep breath), we jumped directly to the migrator tool included in Xcode. Personally, having worked previously on another large Swift codebase, I’ve had my share of pain when it comes to migrations and I didn’t have good memories of previous migrator tools. This time however I was quite surprised with the quality of the suggestions provided, and we ended up accepting most of them. Even enums were properly lowercased and all missing leading dots were added – not bad at all! For the suggestions we weren’t sure about, or that we felt they could be improved or revised later, we decided to accept them while we were on the migrator tool previewer, but take note so we could get back to them. The typical suggestions falling into this category included things like casts between some Swift types and their NS counterparts (e.g. Data to NSData; Calendar to NSCalendar; IndexPath to NSIndexPath, etc) and new optional return types from existing methods that were being migrated as force unwrapped values. Given the fact that most of the files in the project suffered changes, this was a slow and boring process.</p><p>After previewing and migrating all the code, based on the suggestions from the migrator tool, it was time to go through our notes and adjust some of the things we identified earlier. A lot of these involved researching how some of the same operations were supposed to be done in Swift 3 in order to avoid unnecessary casts to NS classes or adding more guard statements to deal with new optional return types in a safer way. Although we can’t really say it was a hard task, it was definitely time consuming — and we still had the main Yoyo Wallet project waiting… 😞</p><p>The process used on the Yoyo Wallet project was pretty much the same: 1) start by updating its dependencies to support Swift 3; 2) Run the migrator tool previewer and go through every single suggestion, taking notes to revise it later if necessary; 3) go through our notes and make any necessary changes. Only this time we had almost 3x more lines of code to migrate!</p><h3>Conclusions</h3><p>Overall, the whole process of migrating both projects to Swift 3 took around 2 weeks with two iOS developers working on it. Even though it was time consuming and stressful at times in the end it was quite rewarding: we are now up to date with the latest Swift version, we can use the latest version of Xcode and, most importantly, we can start developing new features without that awkward feeling that were just accumulating more and more code that would need to be migrated in the future. At least until Swift 4 arrives! 😂</p><p>Thanks to <a href="https://twitter.com/taxomania">@taxomania</a> and <a href="http://twitter.com/TomGoesRAWRr">@TomGoesRAWRr</a> for the feedback provided before the story was published.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9863ddccff1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/yoyo-engineering/migrating-yoyo-wallet-to-swift-3-f9863ddccff1">Migrating Yoyo Wallet to Swift 3</a> was originally published in <a href="https://medium.com/yoyo-engineering">Yoyo Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RxMediaPicker — picking photos and videos the cool kids’ way!]]></title>
            <link>https://medium.com/@ruipfcosta/rxmediapicker-picking-photos-and-videos-the-cool-kids-way-4df81df0c778?source=rss-bb4d09a25fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/4df81df0c778</guid>
            <category><![CDATA[rxswift]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Rui Costa]]></dc:creator>
            <pubDate>Wed, 10 Feb 2016 11:17:14 GMT</pubDate>
            <atom:updated>2016-02-12T14:17:48.529Z</atom:updated>
            <content:encoded><![CDATA[<p>If you ever used UIImagePickerController in your iOS apps and you didn’t like the experience, there are probably a few reasons that explain it: it gets a little verbose and difficult to reuse, you need to add some boilerplate to your screens and its interface is a little messy with several properties meant to be used in different situations. If that’s the case, you should try <a href="https://github.com/ruipfcosta/RxMediaPicker">RxMediaPicker</a>!</p><p><a href="https://github.com/ruipfcosta/RxMediaPicker">RxMediaPicker</a> is a RxSwift wrapper built around UIImagePickerController consisting in a simple interface for common actions like picking photos or videos stored on the device, recording a video or taking photos, etc. And, at the same time, it attempts to provide a solution to ease all the aforementioned issues, offering the following features:</p><ul><li>RxSwift based wrapper built around UIImagePickerController;</li><li>Provides an interface for common operations like picking photos from the library, recording videos, etc;</li><li>Handles edited videos properly — something UIImagePickerController doesn’t do for you!</li><li>Decouples the typical UIImagePickerController boilerplate from your code;</li><li>Reduces the complexity when compared to UIImagePickerController;</li><li>Separates video operations from photos operations;</li><li>Easy to integrate and reuse across your app.</li></ul><h4>Available operations</h4><p>Based on their names, the operations available on RxMediaPicker should be self-explanatory. You can record a video, or pick an existing one stored on the device, the same being available for photos as well.</p><p><strong>Record video:</strong></p><pre>func <strong>recordVideo</strong>(device: UIImagePickerControllerCameraDevice = .Rear, quality: UIImagePickerControllerQualityType = .TypeMedium, maximumDuration: NSTimeInterval = 600, editable: Bool = false) -&gt; <strong>Observable&lt;NSURL&gt;</strong></pre><p><strong>Pick video:</strong></p><pre>func <strong>selectVideo</strong>(source: UIImagePickerControllerSourceType = .PhotoLibrary, maximumDuration: NSTimeInterval = 600, editable: Bool = false) -&gt; <strong>Observable&lt;NSURL&gt;</strong></pre><p><strong>Take photo</strong>:</p><pre>func <strong>takePhoto</strong>(device: UIImagePickerControllerCameraDevice = .Rear, flashMode: UIImagePickerControllerCameraFlashMode = .Auto, editable: Bool = false) -&gt; <strong>Observable&lt;(UIImage, UIImage?)&gt;</strong></pre><p><strong>Pick image</strong>:</p><pre>func <strong>selectImage</strong>(source: UIImagePickerControllerSourceType = .PhotoLibrary, editable: Bool = false) -&gt; <strong>Observable&lt;(UIImage, UIImage?)&gt;</strong></pre><p>If you’re familiar with RxSwift already, using the available operations should be straightforward: for videos you get an Observable which gives you back the video URL; for photos you get an Observable which gives you back a tuple containing the original photo and an optional edited photo (in case you made any edits).</p><p>An example recording a video would look as simple as this:</p><pre>import RxMediaPicker<br>import RxSwift<br><br>var picker: RxMediaPicker!<br>let disposeBag = DisposeBag()<br><br>override func viewDidLoad() {<br>    super.viewDidLoad()<br>    picker = RxMediaPicker(delegate: self)<br>}<br><br>func recordVideo() {<br>    picker.recordVideo(maximumDuration: 10, editable: true)<br>        .observeOn(MainScheduler.instance)<br>        .subscribe(onNext: { url in<br>            // Do something with the video url obtained!<br>        }, onError: { error in<br>            print(&quot;Error occurred!&quot;)<br>        }, onCompleted: {<br>            print(&quot;Completed&quot;)<br>        }, onDisposed: {<br>            print(&quot;Disposed&quot;)<br>        })<br>        .addDisposableTo(disposeBag)<br>}</pre><p>For a sample app have a look the repository at <a href="https://github.com/ruipfcosta/RxMediaPicker">https://github.com/ruipfcosta/RxMediaPicker</a>. Bug reports and pull requests are welcome!</p><p>If you have any questions get in touch on Twitter <a href="https://twitter.com/ruipfcosta">@ruipfcosta</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4df81df0c778" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When functional meets Swift — 5 useful libraries for your apps]]></title>
            <link>https://medium.com/@ruipfcosta/when-functional-meets-swift-5-useful-libraries-to-use-on-your-apps-1e10b65e733?source=rss-bb4d09a25fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e10b65e733</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Rui Costa]]></dc:creator>
            <pubDate>Sat, 26 Dec 2015 15:12:38 GMT</pubDate>
            <atom:updated>2015-12-26T15:20:13.290Z</atom:updated>
            <content:encoded><![CDATA[<p>Want it or not, functional programming is here to stay. Even more mainstream languages are adopting functional concepts and getting inspiration out of functional languages, so if you haven’t started looking into it yet don’t waste any more time!</p><p>If you are doing Swift development you should definitely pay attention to these 5 awesome functional programming libraries:</p><h3><a href="https://github.com/typelift/Swiftz"><strong>Swiftz</strong></a></h3><p>Swiftz is a Swift library for functional programming. It defines functional data structures, functions, idioms, and extensions that augment the Swift standard library. It draws inspiration from a number of functional libraries and languages. Chief among them are <a href="https://github.com/scalaz/scalaz">Scalaz</a>, <a href="https://hackage.haskell.org/package/base">Prelude/Base</a>,<a href="http://sml-family.org/Basis/">SML Basis</a>, and the <a href="http://caml.inria.fr/pub/docs/manual-ocaml/stdlib.html">OCaml Standard Library</a>. Elements of the library rely on their combinatorial semantics to allow declarative ideas to be expressed more clearly in Swift.</p><p>Swiftz implements higher-level data types like Arrows, Lists, HLists, and a number of typeclasses integral to programming with the maximum amount of support from the type system.</p><h3><a href="https://github.com/ReactiveX/RxSwift">RxSwift</a></h3><p>Rx is a <a href="https://youtu.be/looJcaeboBY">generic abstraction of computation</a> expressed through Observable&lt;Element&gt; interface. RxSwift is a Swift version of Rx and, like the original Rx, it intends to enable easy composition of asynchronous operations and event/data streams.</p><p>KVO observing, async operations and streams are all unified under <a href="https://github.com/ReactiveX/RxSwift/blob/master/Documentation/GettingStarted.md#observables-aka-sequences">abstraction of sequence</a>. This is the reason why Rx is so simple, elegant and powerful.</p><h3><a href="https://github.com/thoughtbot/Argo">Argo</a></h3><p>Argo is a library that lets you extract models from JSON or similar structures in a way that’s concise, type-safe, and easy to extend. Using Argo, you won’t need to write validation code to ensure that incoming data is of the right type, or to make sure required data fields aren’t turning up empty. Argo uses Swift’s expressive type system to do that for you, and reports back explicit failure states in case it doesn’t find what you’ve told it to expect.</p><h3><a href="https://github.com/typelift/Tyro">Tyro</a></h3><p>Tyro is another Swift library for Functional JSON parsing and encoding. It has roots in Swiftz and draws inspiration from <a href="https://github.com/bos/aeson">Aeson</a> (from Haskell) and Argo.</p><h3><a href="https://github.com/typelift/Focus">Focus</a></h3><p>Focus is an Optics library for Swift (where Optics includes Lens, Prisms, and Isos) that is inspired by Haskell’s <a href="https://github.com/ekmett/lens">Lens</a> library.</p><p>Which ones of these are you already using in your apps?</p><p>If you have any questions get in touch on Twitter <a href="https://twitter.com/ruipfcosta">@ruipfcosta</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e10b65e733" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A bit of steroids for Auto Layout]]></title>
            <link>https://medium.com/@ruipfcosta/a-bit-of-steroids-for-auto-layout-27ccb00d7fdc?source=rss-bb4d09a25fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/27ccb00d7fdc</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[autolayout]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Rui Costa]]></dc:creator>
            <pubDate>Wed, 23 Dec 2015 13:45:21 GMT</pubDate>
            <atom:updated>2015-12-23T13:46:28.038Z</atom:updated>
            <content:encoded><![CDATA[<p>Auto Layout is a constraint-based system that allows the creation of adaptive interfaces, making it easy to manage different screen sizes/orientations in your apps. What I like about Auto Layout, specially when doing it programmatically, is its expressiveness. You can look at the constraints and quickly understand what is going on with the views on the screen (or at least you should be able to!). It is also relatively easy and quick to add new constraints and integrate them with the existing ones.</p><p>At my current company, Insane Logic, all our UI is done programmatically using Auto Layout. While this gives us a huge flexibility and control, there’s also a downside: our constraint creation code is quite verbose. Swift can make it more readable when compared to Objective-C, but still it doesn’t make a huge difference. Recently I’ve been exploring possible ways to reduce some of the boilerplate when dealing with Auto Layout and, after analysing our typical code, several common patterns emerged:</p><ul><li>When using Visual Format Language to create constraints, most of the times we don’t use a metrics array, and we don’t set any <em>NSLayoutFormatOptions</em>;</li><li>When adding a constraint to an item, most of the times we set the multiplier and constant values to 1 and 0, respectively;</li><li>We frequently center views in their parent/other views, and set the same constraint to multiple views;</li><li>It is common for “<em>NSLayoutConstraint.constraintsWithVisualFormat”</em> to be longer than the actual format string used!</li></ul><p>With that in mind, I wrote a small library called <a href="https://github.com/ruipfcosta/AutoLayoutPlus">AutoLayoutPlus</a> consisting in a set of extensions to <em>NSLayoutConstraint</em> and <em>UIView</em> to makes things a little more manageable and simpler to work with. With AutoLayoutPlus you don’t need to change the way you’ve always worked with Auto Layout, it should feel as natural complement, offering the following features:</p><ul><li>Complement the existing UIKit methods to create constraints for your views;</li><li>Helper methods for the most repetitive tasks (center view, apply the same constraint to multiple views, fill view horizontally, etc);</li><li>Default values for the arguments you usually don’t want to set;</li><li>Makes your code less verbose and easier to follow and maintain;</li><li>AutoLayoutPlus feels natural and provides a similar experience to the methods you are already familiar with.</li></ul><h4>Ok, but what does it look like?</h4><p>Let me show you a couple of examples of how AutoLayoutPlus can be useful. Have a look at this code using Visual Format Language to set multiple constraints to a group of views:</p><pre>NSLayoutConstraint.constraintsWithVisualFormat(“V:|[topContainer(==60)]”, options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)</pre><pre>NSLayoutConstraint.constraintsWithVisualFormat(“H:|[topContainer]|”, options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)</pre><pre>NSLayoutConstraint.constraintsWithVisualFormat(“V:[centerBlueContainer(==200)]”, options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)</pre><pre>NSLayoutConstraint.constraintsWithVisualFormat(“H:[centerBlueContainer(==100)]”, options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)</pre><pre>NSLayoutConstraint.constraintsWithVisualFormat(“V:[centerGreenContainer(==180)]”, options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)</pre><pre>NSLayoutConstraint.constraintsWithVisualFormat(“H:[centerGreenContainer(==80)]”, options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)</pre><pre>NSLayoutConstraint.constraintsWithVisualFormat(“V:[centerOrangeContainer(==160)]”, options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)</pre><pre>NSLayoutConstraint.constraintsWithVisualFormat(“H:[centerOrangeContainer(==60)]”, options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)</pre><p>Since we are not using any metrics array and not setting and NSLayoutFormatOptions, with AutoLayoutPlus it can be worked out to this:</p><pre>NSLayoutConstraint.withFormat([<br>    “V:|[topContainer(==60)]”,<br>    “V:[centerBlueContainer(==200)]”,<br>    “V:[centerGreenContainer(==180)]”,<br>    “V:[centerOrangeContainer(==160)]”,<br>    “V:[bottomContainer]|”,<br>    “H:[centerBlueContainer(==100)]”,<br>    “H:[centerGreenContainer(==80)]”,<br>    “H:[centerOrangeContainer(==60)]”,<br>], views: views)</pre><p>Let’s have a look at another one. In this case the same constraint is being applied to three different views:</p><pre>NSLayoutConstraint(item: centerBlueContainer, attribute: .CenterY, relatedBy: .Equal, toItem: view, attribute: .CenterY, multiplier: 1, constant: 0)<br>NSLayoutConstraint(item: centerGreenContainer, attribute: .CenterY, relatedBy: .Equal, toItem: view, attribute: .CenterY, multiplier: 1, constant: 0)<br>NSLayoutConstraint(item: centerOrangeContainer, attribute: .CenterY, relatedBy: .Equal, toItem: view, attribute: .CenterY, multiplier: 1, constant: 0)</pre><p>With AutoLayoutPlus it becomes easier to identify what is happening:</p><pre>let viewsToCenter = [centerBlueContainer, centerGreenContainer, centerOrangeContainer]</pre><pre>NSLayoutConstraint.constraints(items: viewsToCenter, attribute: .CenterY, relatedBy: .Equal, toItem: view, attribute: .CenterY)</pre><p>Handy, right?</p><p>This article gives a rough idea of what AutoLayoutPlus can offer. To see more examples take a look at the repository at <a href="https://github.com/ruipfcosta/AutoLayoutPlus">https://github.com/ruipfcosta/AutoLayoutPlus</a>, where you can also find a sample app.</p><p>If you have any questions get in touch on Twitter <a href="https://twitter.com/ruipfcosta">@ruipfcosta</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27ccb00d7fdc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SwiftyWalkthrough — adding a great walkthrough experience to your iOS apps]]></title>
            <link>https://medium.com/@ruipfcosta/swiftywalkthrough-adding-a-great-walkthrough-experience-to-your-ios-apps-be3cc3523b08?source=rss-bb4d09a25fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/be3cc3523b08</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[onboarding]]></category>
            <dc:creator><![CDATA[Rui Costa]]></dc:creator>
            <pubDate>Mon, 07 Dec 2015 18:25:54 GMT</pubDate>
            <atom:updated>2015-12-08T10:34:48.828Z</atom:updated>
            <content:encoded><![CDATA[<p>A walkthrough can provide a great way to give users some insight of what your app can do. Although it doesn’t make sense to include one in every single app without a reason — you should aim for a clear and self-explanatory UI/UX in the first place, which can be just as helpful — a walkthrough may be an interesting solution in some scenarios such as welcoming users the first time they log into the app, showing them new or hidden functionality, settings, etc.<br>After spending some time at work searching for a walkthrough library to use in our <a href="https://twitter.com/mychoicepad">MyChoicePad</a> app and not being satisfied with what was available, I ended up creating my own library — <a href="https://github.com/ruipfcosta/SwiftyWalkthrough">SwiftyWalkthrough</a><strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*P28ShJNatqW5TmL3fiaznQ.gif" /><figcaption>Example usage demo</figcaption></figure><p>SwiftyWalkthrough is a Swift library for adding great walkthrough experiences in your iOS apps. You can use it to guide users through the app, step by step, in a predefined way controlled by you. SwiftyWalkthrough was created with a few ideas in mind:</p><ul><li>Allow users to interact with the app, controlling exactly which views are accessible in a given moment;</li><li>Possibility to extend a walkthrough across multiple screens;</li><li>Minimal effort to integrate in an existing app, even if the app wasn’t initially implemented having a walkthrough in mind;</li><li>And of course, to be as simple as possible.</li></ul><p>Note that, by default, the library only provides the mechanism to block the access to your views and cut holes to access them, so it’s up to you to customize the UI to meet your specific needs/requirements. This is how SwiftyWalkthrough was customised in MyChoicePad to help users fill their profile details after the first successful login:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*gnWKQ8HkOfe4C-dVcc1Xtg.gif" /><figcaption>SwiftyWalkthrough usage in MyChoicePad</figcaption></figure><h4>Using SwiftyWalkthrough</h4><p>After installing the library — both Carthage and CocoaPods options are available — the first step will be import SwiftyWalkthrough and (ideally) subclass <em>WalkthroughView</em>:</p><pre>import SwiftyWalkthrough<br><br>class CustomWalkthroughView: WalkthroughView {<br>    // customize it by adding your subviews, etc<br>}</pre><p>Start the walkthrough in your view controller using the custom <em>WalkthroughView</em>:</p><pre>let myCustomWalkthrough = CustomWalkthroughView()<br>startWalkthrough(myCustomWalkthrough)</pre><p>Cut holes on the overlay for the views you want to expose. You can also add some extra padding or define a corner radius to the view frame using a <em>ViewDescriptor</em>:</p><pre>walkthroughView?.cutHolesForViews([nameField])</pre><pre>let descriptors = [ViewDescriptor(view: showProfileButton, extraPaddingX: 20, extraPaddingY: 10, cornerRadius: 10)]<br><br>walkthroughView?.cutHolesForViewDescriptors(descriptors)</pre><p>And, when the walkthrough finishes:</p><pre>finishWalkthrough()</pre><h4>Where to go from here?</h4><p>This article introduces the SwiftyWalkthrough library as an option to consider if you’re planning to add a walkthrough to your iOS app. It doesn’t cover all the details intentionally, so if you‘re interested in knowing a little more or check the example application, have a look at <a href="https://github.com/ruipfcosta/SwiftyWalkthrough">https://github.com/ruipfcosta/SwiftyWalkthrough</a>.</p><p>If you have any questions get in touch on Twitter <a href="https://twitter.com/ruipfcosta">@ruipfcosta</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be3cc3523b08" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Saving precious time when building Carthage dependencies]]></title>
            <link>https://medium.com/@ruipfcosta/saving-precious-time-when-building-carthage-dependencies-486225eb93ca?source=rss-bb4d09a25fe------2</link>
            <guid isPermaLink="false">https://medium.com/p/486225eb93ca</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[carthage]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Rui Costa]]></dc:creator>
            <pubDate>Fri, 27 Nov 2015 23:42:44 GMT</pubDate>
            <atom:updated>2018-03-28T19:48:35.321Z</atom:updated>
            <content:encoded><![CDATA[<p>If you do Cocoa development, it is likely you have come across with <a href="https://github.com/Carthage/Carthage">Carthage</a> by now. Carthage is intended to be the simplest way to add frameworks to your Cocoa application. Contrary to its “competitor” <a href="https://cocoapods.org/">CocoaPods</a>, Carthage only builds the dependencies and provides you with binary frameworks, leaving you the responsibility to integrate them in your project. No extra nonsense added.</p><p>Although Carthage is a great tool to work with, one the most annoying things about it is that it <a href="https://github.com/Carthage/Carthage/issues/610">doesn’t have the ability to build a single dependency</a>: if you add a new entry to your Cartfile, or if you want to update a specific one, all dependencies will be rebuilt. This may not seem a huge problem at first, probably your Cartfile is left untouched for days or even weeks. However, recently at work we decided to extract part of our app into a framework in a separate project. Unfortunately, this requires us to run <em>carthage update</em> more often. Considering the number of dependencies on our Cartfile and the amount of time necessary to build them, this was becoming painful.</p><h4>So, how to workaround the problem?</h4><p>What if you build a single dependency alone, and then integrate it with the rest of your frameworks? Well, that was my approach: I wrote a <a href="https://github.com/ruipfcosta/carthage-workarounds#carthage-buildsh">shell script</a> that takes the dependency you want to add or update, builds it in a separate directory and integrates it back into your existing Carthage folder and Cartfile. And guess what, it does the job!</p><h4>Usage</h4><p>Get <a href="https://github.com/ruipfcosta/carthage-workarounds#carthage-buildsh"><strong>carthage-build.sh</strong></a><strong> </strong>and simply run it from the directory containing your Cartfile/Carthage directory:</p><pre>./carthage-build.sh -d &#39;github &quot;ruipfcosta/AutoLayoutPlus&quot;&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*W_AasgtlLOAv1zP3ci9sAA.gif" /><figcaption>Demo</figcaption></figure><p>For more information, check the repository <a href="https://github.com/ruipfcosta/carthage-workarounds">here</a>.</p><p>If you have any questions, comments or thoughts get in touch on Twitter <a href="https://twitter.com/ruipfcosta">@ruipfcosta</a>.</p><p>Thanks for reading! 💯</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=486225eb93ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>