<?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 Giuseppe Capoluongo on Medium]]></title>
        <description><![CDATA[Stories by Giuseppe Capoluongo on Medium]]></description>
        <link>https://medium.com/@giusecapo?source=rss-30f845f03c30------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*DwJ5Ie-iN8fi1OEBsOojUQ.jpeg</url>
            <title>Stories by Giuseppe Capoluongo on Medium</title>
            <link>https://medium.com/@giusecapo?source=rss-30f845f03c30------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 18:27:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@giusecapo/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[Self-sizing UICollectionViewCell: the quickest and simplest way]]></title>
            <link>https://medium.com/@giusecapo/self-sizing-uicollectionviewcell-the-quickest-and-simplest-way-94e8d1c89594?source=rss-30f845f03c30------2</link>
            <guid isPermaLink="false">https://medium.com/p/94e8d1c89594</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[uicollectionview]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Giuseppe Capoluongo]]></dc:creator>
            <pubDate>Fri, 12 Jul 2019 08:11:51 GMT</pubDate>
            <atom:updated>2019-07-12T11:39:23.331Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7hhunWfPaeg_HohwR55NqQ.png" /></figure><p>Okay, so you have been searching for <strong>how to create self-sizing UICollectionViewCell</strong> for minutes, maybe hours and all you’ve got is dozens of lines of not working code. I know, I have too.</p><p>Basically, the problem is that Swift and UIKit has been updated a lot since Apple first introduced self-sizing cells in 2014. In this article I will show you the simplest solution I found and used for my projects.</p><p>This solution <strong>works for Swift 4</strong> and<strong> iOS 12,</strong> I personally tested it on Xcode 10.2.1.</p><p><strong>Simple as 1, 2, 3</strong></p><ol><li>Create a custom UICollectionViewCell and use Auto-Layout to draw the content: <strong>everything should be put inside a parent UIView. This view must have</strong> <strong>top, bottom, left and right constraints.</strong> I call it “mainView”;</li><li>Write these lines of code inside the <em>viewDidLoad</em> function of the ViewController that hosts the CollectionView. Note that I use <em>UICollectionViewFlowLayout.automaticSize</em> that, according to Apple Documentation, has been introduced with iOS 10, and I found it’s the only working way.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8954da7d802128b98769e8de3791e8c/href">https://medium.com/media/e8954da7d802128b98769e8de3791e8c/href</a></iframe><p>3. Last rule is: if you want the cell height to be dynamic, <strong>you need to set a constraint for the width</strong> and the other way around. In my case, I wanted the height to be dynamic, so inside my custom UICollectionViewCell class, I just put this code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da2a9f8fa67b8652d3ea9c2cba34de2c/href">https://medium.com/media/da2a9f8fa67b8652d3ea9c2cba34de2c/href</a></iframe><blockquote>Please note that I set my cell width constraint equal to screen width — 40 because I wanted a left and a right margin of 20.</blockquote><p>We’re done!</p><p>Just to be clear, that’s a screenshot of the custom cell Storyboard:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9oLIHx_DUwPqHLDdgXBHFQ.png" /><figcaption>The magic MainView with its constraint makes self-sizing possible</figcaption></figure><p>Here we go! The simplest way to create self-sizing cell.</p><p>Please let me know if you use different methods and if there is a even more efficient way to achieve this result!</p><p>Have a nice dev day,</p><p>Giuseppe.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94e8d1c89594" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Boost your Swift code with simple tips]]></title>
            <link>https://medium.com/@giusecapo/boost-your-swift-code-with-simple-tips-c308c78afeb5?source=rss-30f845f03c30------2</link>
            <guid isPermaLink="false">https://medium.com/p/c308c78afeb5</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Giuseppe Capoluongo]]></dc:creator>
            <pubDate>Fri, 06 Oct 2017 19:07:40 GMT</pubDate>
            <atom:updated>2017-10-09T15:39:03.014Z</atom:updated>
            <content:encoded><![CDATA[<h4>AKA, WHAT I’VE REALISED AFTER 1-YEAR iOS DEVELOPER JOB</h4><p>During the last year I’ve worked on different iOS applications as a freelance developer. It has been a fulfilling yet challenging experience. Most important, it’s been cool and I enjoyed it.</p><p>At first I was commissioned a bug-fix on a pretty old Objective-C app. Well, it was terrifying actually. The code was a mess: no comments, no wiki and a lot of duplicate stuff. But I made it, I fixed it and I felt good.</p><p>Then cool jobs came, new projects with great UI to design and fresh Swift code to write. Open Xcode, write things, test ’em and share results with absolutely-not-caring friends. That’s basically a drug for most of us.</p><p>When I started, however, I made mistakes. I still do. Every developer knows how important is the self criticism. Most of us are perfectionists: not only we like to write good and super-optimized code, but we want it to be damn beautiful to read.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0syxG6pVAgyWwItiegWS8g.jpeg" /><figcaption>Basically, a typical developer day.</figcaption></figure><p>Anyway, I can’t wait to be a perfect coder. So here we are, I’d like to share with you some tips and lessons I’ve learned during this last dev year.</p><h4>Comment, comment, comment</h4><p>Really, how much does it take to write a good comment? 10 sec? 20 sec? Well, do it! There’s nothing better that a well commented code. As a developer you will almost never work alone. Make your dev partners’ life easier by commenting your code. Unless you hate ’em: in this case, do not comment at all.</p><p>But comments are very useful for you too. If I write a bunch of code in a super-focused-zen-style session then I come back on this one after two or three days, I can’t almost remember anything. How many times have you been in this situation? That’s because you lost the momentum. In these cases, comments remind me how and why I wrote a certain thing.</p><p>Also remember that too much comment is confusing. Use with moderation and when it’s useful.</p><h4>Keep your code organized</h4><p>This guy here</p><pre>// Mark: – </pre><p>Well, it must become your best friend.</p><p>Mark portions of code is very important and helps you to quick switch from a point to another. Just consider your code a blog article: marks are subtitle.</p><p>Another good approach to keep your code organized is to use extensions instead of a single class with multiple protocols.</p><pre>class ViewController: UIViewController {<br>  // things happen<br>}<br><br>// MARK: - UITableViewDataSource<br>extension ViewController: UICollectionViewDataSource {<br>  // table view data source methods<br>}<br><br>// MARK: - UIScrollViewDelegate<br>extension ViewController: UIScrollViewDelegate {<br>  // scroll view delegate methods<br>}</pre><p>By doing this, you’ll be at least 200% more productive and will avoid mess up.</p><h4>Give a reasonable name to things</h4><p>Functions, variables, constants, enumarations, classes etc. have a name so it is easier for the developer understand what they do. But giving wrong names is useless and stressing for you and other developers.</p><p>Try this tip: learn how iOS SDK names are made and try to do the same. For examples, avoid redundancy between function name and its properties.</p><pre>// Do not use this<br>function saveDataForUser(data: Data, user: User)</pre><pre>// Use this as it&#39;s more clean<br>function saveData(_ data: Data, forUser user: User)</pre><p>Also gives variables and constants (and use these two in the right way!) an easy-to-understand name.</p><p>Especially when it comes to write flags, be sure that’s clear if they refer to past or future.</p><pre>// Nope: data have to load? data already loaded? I don&#39;t know<br>var dataLoad: Bool</pre><pre>// Yep: now it&#39;s clear, data already loaded<br>var dataDidLoad: Bool</pre><h4>Use Git</h4><p>One of the first thing I had to do when I started as a developer, was to learn Git. In the beginning, GitHub was to me a bit difficult to understand, but when I did, well, I fell in love with it.</p><p>GitHub is not just your web-based version control system (aka “OMG I made a mess, let’s revert these changes”) but a beautiful place where you can document your code and talk about it with other developers or team mates.</p><p>So use it, use “Wiki” to document your code as a coding journal. Keep it updated. Also use “Issues” to have discussions with others about bugs or new features. Learn how to use branches and to collaborate with others. It is a great skill for a developer and for sure, a must-have for your resume.</p><p>I think that’s a great way to grow as a developer, share knowledge with others, keep clean and documented code while building a significant portfolio.</p><h4>Refactor</h4><p>Usually, code becomes a giant monster. This happens when we are so focused on make things work that we forget to delete that commented line or to move that function here and there. That’s okay if it’s temporary but be sure to order things once you finish your work. When necessary, create classes or structures and learn how to use the “Refactor” function in Xcode.</p><p>To avoid “I’ll do this later” trap I use this approach: every time I finish some task or long coding session, before pushing my code on GitHub, I make a last commit. It’s the “refactor and clean code” (well, not always this name) commit and it ends my session.</p><pre>git commit -am &quot;refactor and clean code&quot;</pre><p>After this I go dinner/friends/girlfriend/whatever. Remember: after, never before.</p><pre>git push</pre><pre>🍹</pre><h4><strong>Conclusion</strong></h4><p>These are just some simple generic tips you can keep in mind when working on projects. I’m happy I’ve learned these lessons during the past year. Please feel free to share with me what made you more productive and I will surely add your tips to this list!</p><p>Keep building apps!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c308c78afeb5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>