<?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 Arthur Crocquevieille on Medium]]></title>
        <description><![CDATA[Stories by Arthur Crocquevieille on Medium]]></description>
        <link>https://medium.com/@arthur.crocquevieille?source=rss-25270b717317------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fHcMBjMTFJHftHSULBP5Fw@2x.jpeg</url>
            <title>Stories by Arthur Crocquevieille on Medium</title>
            <link>https://medium.com/@arthur.crocquevieille?source=rss-25270b717317------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 12:20:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arthur.crocquevieille/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[Creating custom UIView from a XIB in Swift]]></title>
            <link>https://medium.com/@arthur.crocquevieille/creating-custom-uiview-from-a-xib-in-swift-956b419f83cd?source=rss-25270b717317------2</link>
            <guid isPermaLink="false">https://medium.com/p/956b419f83cd</guid>
            <category><![CDATA[uiview]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[custom]]></category>
            <dc:creator><![CDATA[Arthur Crocquevieille]]></dc:creator>
            <pubDate>Sun, 02 Feb 2020 19:04:11 GMT</pubDate>
            <atom:updated>2020-02-02T19:04:11.809Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating a custom UIView from a Xib in Swift</h3><p>How to create custom UIViews to improve your project?</p><h3>Why are custom views important? 🧐</h3><p>Creating custom views is an underrated habit that can benefit any codebase for a variety of reasons.</p><h4><strong>Reusability</strong></h4><p>Very often, the same group of design elements will be on multiple screens across an app. It makes sense to group them in a custom UIView to reuse the same design and logic at multiple places.</p><ul><li>Enables reusable design and code</li><li>Saves time</li><li>Facilitates changes</li></ul><h4><strong>Readability</strong></h4><p>When a screen has many design elements, the UIViewController associated with it can get messy.</p><ul><li>A lot of outlets</li><li>A lot of configuration logic</li></ul><p>Grouping those elements in a custom UIView move the outlets and the configuration logic to the custom view, making the view controller smaller, easier to read and maintain.</p><h4>Testability</h4><p>Testing every state of a view controller that has a lot of outlets and design logic can be time-consuming and hard to maintain. However, if the view controller is built from a few custom views, those can be tested independently. This improves your tests and make them:</p><ul><li>Easier to maintain</li><li>Smaller and faster to write</li></ul><h3>How can I create a custom UIView from a Xib? 🛠</h3><p>It is relatively easy to create a custom UIView from a Xib in Swift. There are multiple steps to it though. It all starts with a simple protocol.</p><h4>Protocol</h4><p>First, we need a protocol to give a subclass of UIView the ability to attach the content of Xib to its content view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tNKnzVxddG2NGeLdfpfV2g.png" /><figcaption>1. CustomViewProtocol</figcaption></figure><h4>Xib file and UIView subclass</h4><p>Let’s say our custom view is called MyCustomView. The creation process would be the following:</p><ul><li>Create a UIViewsubclass called MyCustomView</li><li>Create a Xib file called MyCustomView</li></ul><p>Then, we need MyCustomView to conform to CustomViewProtocol.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OYAco0RWYn1weMTkwY7NFg.gif" /><figcaption>2. MyCustomView confirming to CustomViewProtocol</figcaption></figure><p>After this step, it is crucial to make sure the commonInit(for customViewName: String) method is called when the custom UIView is initialized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*74C_xKBOjUUJaSZInW1U6Q.png" /></figure><p>That’s it, you have attached the content of a Xib to your custom UIView.</p><h4>Usage</h4><p>To use your custom view, add a UIView to your UIViewController in storyboard and set its class to be your custom view. That’s it! 🎉</p><h4>Note</h4><p>If you need to handle certain events happening in your custom view from your view controller I would recommend using the delegate pattern.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=956b419f83cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple dependency injection]]></title>
            <link>https://medium.com/@arthur.crocquevieille/simple-dependency-injection-41837582f2d0?source=rss-25270b717317------2</link>
            <guid isPermaLink="false">https://medium.com/p/41837582f2d0</guid>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[2020]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Arthur Crocquevieille]]></dc:creator>
            <pubDate>Sun, 19 Jan 2020 17:49:46 GMT</pubDate>
            <atom:updated>2020-01-19T17:49:46.024Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dependency injection</h3><h4>What is dependency injection?</h4><p>Dependency injection is the idea to inject an outside object into another instead of creating it internally. So instead of doing something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UB3tFSzdi5DIF3VcCgiLTw.png" /><figcaption>1. Internally created object</figcaption></figure><p>you would do something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ev6JwG5LCgRq7X3xpAkj8Q.png" /><figcaption>2. Injected object</figcaption></figure><p>It’s a very simple principle to follow. It encourages the single responsibility principle, it improves the maintainability, reusability, and testability of a codebase.</p><h4>What does dependency injection bring to a project?</h4><p>When working on a codebase, you want to avoid tight coupling as much as possible. Tight coupling is when some objects are highly dependent on each other. It usually implies that one object has too many responsibilities. Having such a situation complexifies the codebase and makes testing very difficult.</p><p>To overcome this situation, we need to split our app into loosely-coupled components. A great way to achieve this is to enforce dependency injection.</p><p>By extracting each of the responsibilities of an object to external objects, dependency injection will make sure there are as little as tightly-coupled components as possible. This will enforce:</p><ul><li><strong>Readable code</strong>: objects will have fewer responsibilities hence files will be smaller and logic will be simpler. That’ll make your code a lot more readable overall.</li><li><strong>Reusable code</strong>: each object will have only one responsibility which means you will be able to reuse components more often.</li><li><strong>Maintainable code</strong>: objects will be smaller and will contain less logic, it will be easier to make changes to existing objects.</li><li><strong>Testable code</strong>: because dependencies are injected you can easily replace them with mock objects to test the behavior of a class under specific configurations.</li></ul><h4>How do we implement it?</h4><ol><li>The first step is to identify all the responsibilities of an object. This will help you to assess if an object is doing too much and needs to be refactored.</li><li>The second step is to separate each responsibility in an object. This will make your code more reusable, easy to maintain and a lot more readable.</li><li>The third step is to inject those single responsibility objects into the refactored object using its initializer.</li></ol><p>Following those steeped allowed me to refactor and improve old codebases fairly easily.</p><p>Dependency injection comes with some downsides for bigger projects though.</p><ul><li>Increases the number of classes</li><li>Increases the amount of boilerplate code</li><li>Time-consuming</li></ul><p>To fix those issues I used the following frameworks.</p><ul><li><a href="https://github.com/Swinject/Swinject">Swinject</a> is a dependency injection framework that helps your app split into loosely-coupled components.</li><li><a href="https://github.com/Swinject/SwinjectStoryboard">SwinjectStoryboard</a> is a Swinject extension for automatic dependency injection via Storyboard.</li><li><a href="https://github.com/Swinject/SwinjectAutoregistration">SwinjectAutoRegistration </a>is an extension of Swinject that allows you to automatically register your services and greatly reduce the amount of boilerplate code.</li></ul><h4>Results</h4><p>As a result of proper dependency injection, we now have a codebase built with small objects that have a single responsibility and are easy to test.</p><p>Introducing unit testing to a project is key to:</p><ul><li>Validate bug fixes and features</li><li>Document complex logic</li><li>Enforce good code quality</li></ul><p>Personally, proper dependency injection was a real game-changer. It enabled me to write cleaner code and learn unit testing.</p><p>I have been using <a href="https://github.com/pointfreeco/swift-snapshot-testing">SnapshotTesting</a>, <a href="https://github.com/MakeAWishFoundation/SwiftyMocky">SwiftyMocky</a>, and <a href="https://github.com/Quick/Nimble">Nimble</a> for a while now and it’s a combination that works very well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41837582f2d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>