<?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 Code in Swift on Medium]]></title>
        <description><![CDATA[Stories by Code in Swift on Medium]]></description>
        <link>https://medium.com/@code-in-swift?source=rss-59a83c429246------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*f6Lt6zVWa91Lg5hq.jpg</url>
            <title>Stories by Code in Swift on Medium</title>
            <link>https://medium.com/@code-in-swift?source=rss-59a83c429246------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 15:02:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@code-in-swift/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] Don’t use a protocol when a struct would do a better job]]></title>
            <link>https://code-in-swift.medium.com/ios-swift-protocol-is-not-always-a-solution-95bba0541d6d?source=rss-59a83c429246------2</link>
            <guid isPermaLink="false">https://medium.com/p/95bba0541d6d</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift-tutorial]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-tips]]></category>
            <dc:creator><![CDATA[Code in Swift]]></dc:creator>
            <pubDate>Wed, 30 Mar 2022 14:27:20 GMT</pubDate>
            <atom:updated>2022-04-03T06:47:14.035Z</atom:updated>
            <content:encoded><![CDATA[<p>In the previous <a href="https://codeinswift.io/building-a-selection-list-using-generics-c7c79e004dd5">article</a> we created a selection list that can work with any value that conforms to <strong>Selectable</strong> protocol.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a29ab68a43dec7b6cacfa6b4d97c007/href">https://medium.com/media/0a29ab68a43dec7b6cacfa6b4d97c007/href</a></iframe><p>This protocol is used for two things: providing a title and an optional icon for displaying in our list and making sure that the models can be compared with the help of the <a href="https://developer.apple.com/documentation/swift/equatable"><strong>Equatable</strong></a> protocol.</p><p>It works well and at first glance there’s nothing wrong with it. But it actually has a problem that’s been bothering me for a while.</p><p>Imagine we have a <strong>Driver</strong> model that looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d18692222b203e990dde9f1adfc6253/href">https://medium.com/media/2d18692222b203e990dde9f1adfc6253/href</a></iframe><p>We want it to conform to <strong>Selectable</strong> and it’s very easy to do. In fact we already have an <strong>icon</strong> property, so it feels like half of the work is done.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3a14628bdfa91d3c71f2c0d3cc81aea/href">https://medium.com/media/c3a14628bdfa91d3c71f2c0d3cc81aea/href</a></iframe><p>Unfortunately this <strong>won’t compile</strong>. The <strong>Selectable</strong> protocol expects an optional <strong>icon</strong> property, and <strong>Driver</strong>’s one isn’t. It seems counterintuitive that you can’t satisfy an optional requirement with a regular one, but that’s how the compiler works.</p><h3>Issues with protocols</h3><p>There are also other probles with this solution.</p><p>Let’s imagine that <strong>Driver</strong>’s icon property is optional and fits the protocols requirements. We still have part of our conformance (icon) in the struct and the other part (title) in the extension. It’s not a big deal, but it makes understanding the code a little bit more difficult. It would be nice if everything was in the same place.</p><p>The other problem is, the <strong>title</strong> property is kind of the same as <strong>name</strong> property, isn’t it? Once again, it makes for messy and non-obvious code. If you encountered both of them in the Xcode’s autocompletion panel, you wouldn’t know which one to use and why.</p><p>Also, imagine that we already have a <strong>title</strong> property in our <strong>Driver</strong> struct but it contains a value that is different from the one we need. What then? Again, it will lead to messy, non-obvious code.</p><p>But most importantly, the model shouldn’t know about the specific UI requirements at all. Providing a title and an icon isn’t its responsibility. So our implementation of <strong>Selectable</strong> protocol is wrong to begin with. In fact, we don’t need it at all.</p><h3>Protocol witnesses</h3><p><strong>Protocol Witness</strong> is a fancy name for a <strong>struct</strong> with generic parameters. There are some great articles about them, the latest I’ve read is <a href="https://medium.com/@riccardocipolleschi/stop-using-protocols-cd63744a3261">this one</a>. They are mainly used to convert problematic protocols into perfectly working generic structs.</p><p>So let’s start by deleting the <strong>Selectable</strong> protocol and removing unnecessary code from our <strong>Driver</strong> struct. The only thing it needs to do is conform to the <a href="https://developer.apple.com/documentation/swift/equatable"><strong>Equatable</strong></a> protocol.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18cfbb03462865f84aca23e2b294eea4/href">https://medium.com/media/18cfbb03462865f84aca23e2b294eea4/href</a></iframe><p>So far, so good. But we need a way to extract a title and an icon from the <strong>Driver</strong> struct (or any other <a href="https://developer.apple.com/documentation/swift/equatable"><strong>Equatable</strong></a> model) to display them in our list. That seems like a job a function would do well. So let’s define such a function and give it a typealias for ease of use.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50b2f37967fc9a19102a5b16a4d42b8d/href">https://medium.com/media/50b2f37967fc9a19102a5b16a4d42b8d/href</a></iframe><p>Now we add it to our <strong>SelectionList</strong> model that is used to simplify initialization of the <strong>SelectionListViewController</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd226f15468f07446522e427b1363d5b/href">https://medium.com/media/bd226f15468f07446522e427b1363d5b/href</a></iframe><p>And here’s how you would use it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b1c2a0b2b693fb03d980b3593753245/href">https://medium.com/media/4b1c2a0b2b693fb03d980b3593753245/href</a></iframe><p><em>If you liked this article please</em><a href="https://twitter.com/senor_ganso/status/1509175725756235778"><em> </em><strong><em>retweet it on Twitter</em></strong></a><em> or share it in any other social network. It helps more than you think!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95bba0541d6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Swift] Building a selection list using Generics]]></title>
            <link>https://code-in-swift.medium.com/building-a-selection-list-using-generics-c7c79e004dd5?source=rss-59a83c429246------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7c79e004dd5</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift-tips]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-tutorial]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Code in Swift]]></dc:creator>
            <pubDate>Sun, 13 Mar 2022 11:54:16 GMT</pubDate>
            <atom:updated>2022-04-03T06:47:18.839Z</atom:updated>
            <content:encoded><![CDATA[<p>Picking something out of a list of values is an incredibly common pattern in iOS. An application may have a dozen of screens like that. Manually writing them again and again is a lot of duplicated code that we don’t really need in our projects. What if we could create a generic view controller that could be reused across screens and projects to pick any kind of values?</p><p>The end result should be something like this, suitable to pick any kind of value:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tl9eZbp7BrYrnmZYRRgoBg.png" /></figure><p>We are going to support both kinds of lists: with icons and without. I’m going to omit most of the <strong>UICollectionView</strong> code in the snippets, but it is included in the <a href="https://github.com/Code-in-Swift/selectionList.ios/tree/using_selectable_protocol">sample project</a>.</p><h3>Selectable protocol</h3><p>As we see on the screenshot above, the basic UI consists of a screen title and a value title. This is going to be the basis of our requirements for the <strong>Selectable</strong> protocol. We’ll also make it conform to <strong>Equatable</strong> protocol so that we can show and scroll to already selected value. It will also allow the caller of the list to understand which value was picked.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a29ab68a43dec7b6cacfa6b4d97c007/href">https://medium.com/media/0a29ab68a43dec7b6cacfa6b4d97c007/href</a></iframe><p>Now we need to conform our model to our protocol. But what if we have no specific model? What if we want to just pick a number? Do we pollute <strong>Int</strong> with our protocol conformance? What if we have two different screens both of which select numbers, what then?</p><h3>Typealiases for selectable types</h3><p>Turns out, that’s not really a problem. A great thing about Swift is that it not only has typealiases, but they can conform to protocols independently of their base type. So if we wanted, for example, to select from a list of Formula 1 seasons all we need to do is this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a04c0d8460940a9ec257ff3a0f750d36/href">https://medium.com/media/a04c0d8460940a9ec257ff3a0f750d36/href</a></iframe><p>To show how to support icons in the list we’ll add another model with information about Formula 1 championship kind.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82afdfb55758cf4b20851dedf053e9c2/href">https://medium.com/media/82afdfb55758cf4b20851dedf053e9c2/href</a></iframe><h3>Generic view controller</h3><p>With the above in place we can start work on our generic <strong>UIViewController</strong>. We’ll need <strong>values</strong> and <strong>selectedValue</strong> properties for a list of possible values and the currently selected value respectively. These values will be displayed using <strong>UICollectionView</strong>, but as I said before, I won’t be including that code into the snippets.</p><p>Since our view controller works with any <strong>Selectable</strong> type, we add it as a <a href="https://docs.swift.org/swift-book/ReferenceManual/GenericParametersAndArguments.html">type argument</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f8e5ebdc5e815abe13a6fc8c8516b62/href">https://medium.com/media/2f8e5ebdc5e815abe13a6fc8c8516b62/href</a></iframe><h3>Returning selected value</h3><p>Now we need a way to return the selected value back to the caller. Generic nature of our selection list makes using delegates for this task a little awkward. The better approach is a callback handler.</p><p>In the callback we need to return two values: the value that was picked and the <strong>SelectionListViewController</strong> itself, so that the caller can dismiss it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1f0a974b17d158028f0a28ad85cccce/href">https://medium.com/media/b1f0a974b17d158028f0a28ad85cccce/href</a></iframe><h3>Showing currently selected value</h3><p>What if some value was already selected? We likely want to highlight it in the list and scroll to it automatically.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/449e267f91be16dbd91d104d319736fe/href">https://medium.com/media/449e267f91be16dbd91d104d319736fe/href</a></iframe><p>If it’s not a first item, we want to show the user that there are more items above the selected one. That’s why we scroll not to the selected item, but to the one directly above it.</p><h3>Usage</h3><p>With the above in place we’re ready to use our selection list. Let’s add some data to our <strong>Season</strong> model and see how we would invoke our <strong>SelectionListViewController</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6bbaaf5d6a30316623bdd96a62055f71/href">https://medium.com/media/6bbaaf5d6a30316623bdd96a62055f71/href</a></iframe><p>Now we can pick a season or championship of Formula 1 with just a few lines of code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4010bce0b349e376232d839db6ebd82e/href">https://medium.com/media/4010bce0b349e376232d839db6ebd82e/href</a></iframe><p>In a future article we’ll see if we can extend this solution to support loading values from API.</p><p><em>Check out sample code </em><a href="https://github.com/Code-in-Swift/selectionList.ios/tree/using_selectable_protocol"><em>here</em></a><em>.</em></p><p><em>If you liked this article please </em><a href="https://twitter.com/senor_ganso/status/1503712346891509760"><strong><em>retweet it on Twitter</em></strong></a><em> or share it in any other social network. It helps more than you think!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7c79e004dd5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Swift] Using Generics to simplify subclassing UIViewController’s view]]></title>
            <link>https://code-in-swift.medium.com/using-generics-to-simplify-subclassing-uiviewcontrollers-view-860c90852e27?source=rss-59a83c429246------2</link>
            <guid isPermaLink="false">https://medium.com/p/860c90852e27</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-tips]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift-tutorial]]></category>
            <category><![CDATA[autolayout]]></category>
            <dc:creator><![CDATA[Code in Swift]]></dc:creator>
            <pubDate>Fri, 11 Mar 2022 12:22:33 GMT</pubDate>
            <atom:updated>2022-04-03T06:47:23.457Z</atom:updated>
            <content:encoded><![CDATA[<p>Before we start with the topic of this article, I’d like to add a little sidenote. For some reason, I see a lot of people creating and storing their subviews in <strong>UIViewControllers</strong> and not in their <strong>UIViews</strong>. In thousands of codebases, even in Apple’s sample code, you can see something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8a1ceb127eb2417e4d596ec0326821b/href">https://medium.com/media/a8a1ceb127eb2417e4d596ec0326821b/href</a></iframe><p>This doesn’t feel right. <strong>UIViewController</strong> should control its views, not create or layout them. But how do you subclass the view of a <strong>UIViewController</strong>?</p><p>What many people don’t realise is that you can easily override the default <strong>UIView</strong> of a <strong>UIViewController</strong> with your own. All you need to do is assign it in <strong>loadView()</strong>. Make sure not to call <strong>super</strong> in your implementation in accordance to Apple’s <a href="https://developer.apple.com/documentation/uikit/uiviewcontroller/1621454-loadview">documentation</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ca4b2e80ee9bc2d6ab0b1ca8a479a20/href">https://medium.com/media/1ca4b2e80ee9bc2d6ab0b1ca8a479a20/href</a></iframe><p>Our current approach presents us with a problem. Our view’s frame is .zero. The iOS will set a proper size for our view but much later. Later than <strong>viewDidLoad()</strong> is called. This might cause problems with auto layout and any calculations involving the view’s size.</p><p>So we need to set the frame of our view in <strong>loadView()</strong> method. But how do we know what values to use? The short answer is: we don’t. Unfortunately the logic of the frame’s calculations is hidden behind a private Apple’s API and we can’t access it. What we can do is use our best guess. And our best guess here is <strong>UIScreen</strong>’s bounds. This is a good default value and in most cases should be equal to the final one.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7659938324c243caa83ee2f417ff1403/href">https://medium.com/media/7659938324c243caa83ee2f417ff1403/href</a></iframe><p>The other problem is the access to <strong>ProductsListView</strong> properties is a little awkward. You need to cast the base <strong>UIView</strong> to <strong>ProductsListView </strong>first and do it in every call every time.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26cc3ee0cd919c254e3c6895055e3518/href">https://medium.com/media/26cc3ee0cd919c254e3c6895055e3518/href</a></iframe><p>This isn’t what we want. But it’s an easy problem to solve. Just declare our <strong>UIView</strong> as a property on the view controller and assign it to the base view later.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fdd7b63a347b272a929030c5c0593319/href">https://medium.com/media/fdd7b63a347b272a929030c5c0593319/href</a></iframe><p>Now you can call it directly and we’re finally ready to move to the topic of this article.</p><p>What we’ve achieved is already good. We moved a lot of logic from <strong>UIViewController</strong> to <strong>UIView</strong>. What we probably want to do next is to make this solution generic, so we don’t have to call <strong>loadView()</strong> and declare the <strong>ui</strong> property manually all the time.</p><p>We can achieve this by creating a generic <strong>UIViewController</strong> subclass that would accept a <strong>UIView</strong> subclass as part of its declaration.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/265baabf11b7b479b5bcc6d2d4ff053a/href">https://medium.com/media/265baabf11b7b479b5bcc6d2d4ff053a/href</a></iframe><p>And now our <strong>ProductsListViewController</strong> becomes as simple as possible.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1d8b2a266a7fc7442b6507849d6bd16/href">https://medium.com/media/d1d8b2a266a7fc7442b6507849d6bd16/href</a></iframe><p><em>If you liked this article please </em><a href="https://twitter.com/senor_ganso/status/1502259700565430274"><strong><em>retweet it on Twitter</em></strong></a><em> or share it in any other social network. It helps more than you think!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=860c90852e27" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to prevent Xcode from asking for ‘required’ initializer ‘init(coder:)’ in every subclass of…]]></title>
            <link>https://code-in-swift.medium.com/how-to-prevent-xcode-asking-for-required-initializer-init-coder-in-every-subclass-of-uiviews-c67054284fc2?source=rss-59a83c429246------2</link>
            <guid isPermaLink="false">https://medium.com/p/c67054284fc2</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-tips]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Code in Swift]]></dc:creator>
            <pubDate>Thu, 10 Mar 2022 13:39:58 GMT</pubDate>
            <atom:updated>2022-03-11T10:55:27.593Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to prevent Xcode from asking for ‘required’ initializer ‘init(coder:)’ in every subclass of UIViews or UIViewControllers</h3><p>If you’re like me and prefer to create your views and view controller in code rather than using storyboards or nibs, then you know how annoying it is that Xcode still forces you to implement <strong>required initializer ‘init(coder:)</strong>.</p><p>Luckily you can use Swift’s <strong>@available </strong>attribute to not only prevent Xcode from requiring unnecessary initializers, but also from showing them in the autocompletion list.</p><p>Here’s how you can do it for <strong>UIViewController</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RiAw2-ROqQ9xL_WuS9f9jA.png" /></figure><p>With this in place, we can create a subclass of <strong>ViewController</strong> and won’t have to implement <strong>required initializer ‘init(coder:) </strong>in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rjp13zuUQ8XH853tOC7W-Q.png" /></figure><p>The same principle can be used for any subclass of <strong>UIView</strong>. The only downside is you have to create a base subclass for all <strong>UIView</strong>’s subclasses (like <strong>UILabel</strong>, <strong>UIButton</strong>, <strong>UITextView</strong> and so on). But these are rarely subclassed, so creating base classes for just <strong>UIViewController</strong> and <strong>UIView</strong> already removes a lot of unnecessary code.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c67054284fc2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How capture lists work and how their behaviour differ for value and reference types in Swift]]></title>
            <link>https://code-in-swift.medium.com/how-capture-lists-work-and-how-their-behaviour-differ-for-value-and-reference-types-in-swift-3d1c50a246cb?source=rss-59a83c429246------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d1c50a246cb</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-fundamentals]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Code in Swift]]></dc:creator>
            <pubDate>Wed, 09 Mar 2022 13:00:33 GMT</pubDate>
            <atom:updated>2022-03-25T08:56:30.012Z</atom:updated>
            <content:encoded><![CDATA[<p>As part of my <a href="https://twitter.com/senor_ganso/status/1501120166884777988">job search</a> I did an automated test at <a href="https://toggl.com/">Toggle</a> which made me realise I forgot a lot of fundamental reasons for why things work the way they work in Swift. I knew correct answers to most of the questions, but I wasn’t always 100% certain why they were correct. So I decided to dig in and research all of them.</p><p>The questions themselves are pretty generic so I won’t try and change them from what they were in the test, I hope the Toggle folks forgive me. Here’s the first one.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c302efe80138ebad59dba9fc600e883/href">https://medium.com/media/8c302efe80138ebad59dba9fc600e883/href</a></iframe><p>So the question is what the print output is going to be. Intuitively it feels the answer is “Sum is 8”. And it is indeed correct. But why?</p><p><strong>Processor</strong> is a value type. So when the <a href="https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#ID544">caputre list</a> creates a <strong>Processor</strong> constant it copies the values from the variable that we declared before the closure. And from then on, these two instances of <strong>Processor </strong>exist completely separately from each other. When we change the .b value of the first instance to 20, the .b value of the second one is not changed.</p><p>If <strong>Processor</strong> was a class and not a struct, the <a href="https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#ID544">capture list</a> would still create a new instance of it but it would point to the same object as the first one. And if you changed the .b value in one of them, it would be changed everywhere. So if it was a class, the answer would be “Sum is 23”.</p><p>But what if we remove the capture list entirely? Would anything change?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74152d0cad2302be5be91f96dd7d1122/href">https://medium.com/media/74152d0cad2302be5be91f96dd7d1122/href</a></iframe><p>Now we don’t create a second instance of <strong>Processor</strong> and work with the first one directly. So in both cases the .b value is changed to 20 before the sum is calculated. Therefore, for both value and reference types the answer is “Sum is 23”.</p><p><em>If you liked this article please </em><strong><em>share it on Twitter</em></strong><em> or any other social network. It helps more than you think!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d1c50a246cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to change scroll direction of a collection view using UICollectionViewCompositionalLayout]]></title>
            <link>https://code-in-swift.medium.com/how-to-change-scroll-direction-of-a-collection-view-using-uicollectionviewcompositionallayout-c84d4cc24770?source=rss-59a83c429246------2</link>
            <guid isPermaLink="false">https://medium.com/p/c84d4cc24770</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[swift-tips]]></category>
            <dc:creator><![CDATA[Code in Swift]]></dc:creator>
            <pubDate>Tue, 08 Mar 2022 16:06:32 GMT</pubDate>
            <atom:updated>2022-03-08T16:34:56.630Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://developer.apple.com/documentation/uikit/uicollectionviewcompositionallayoutconfiguration">UICollectionViewCompositionalLayoutConfiguration</a> has a <a href="https://developer.apple.com/documentation/uikit/uicollectionviewcompositionallayoutconfiguration/3199222-scrolldirection">scrollDirection</a> property. Changing it will affect the whole collection view.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/497a8a69676cf1e143d3af5aed74c761/href">https://medium.com/media/497a8a69676cf1e143d3af5aed74c761/href</a></iframe><p>You can also set orthogonal scroll direction for sections using <a href="https://developer.apple.com/documentation/uikit/nscollectionlayoutsection/3199094-orthogonalscrollingbehavior">orthogonalScrollingBehavior</a> property of a <a href="https://developer.apple.com/documentation/uikit/nscollectionlayoutsection">NSCollectionLayoutSection</a>. So, for example, if your collection view has vertical scroll direction, you can add horizontal direction for specific sections. This makes layouts like the AppStore or Music apps have trivial to do.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1da534894c4038160548c99cc6a775b2/href">https://medium.com/media/1da534894c4038160548c99cc6a775b2/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c84d4cc24770" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>