<?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 John Estropia on Medium]]></title>
        <description><![CDATA[Stories by John Estropia on Medium]]></description>
        <link>https://medium.com/@john.estropia?source=rss-834daea6eec5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nkPiZ2N-SgEUQ7wKaqTNjw.jpeg</url>
            <title>Stories by John Estropia on Medium</title>
            <link>https://medium.com/@john.estropia?source=rss-834daea6eec5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 19:33:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@john.estropia/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[A Skeptical iOS Developer’s Take on AI in 2025]]></title>
            <link>https://medium.com/eureka-engineering/a-skeptical-ios-developers-take-on-ai-in-2025-ea6d7c2246f8?source=rss-834daea6eec5------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea6d7c2246f8</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[John Estropia]]></dc:creator>
            <pubDate>Mon, 08 Dec 2025 22:02:11 GMT</pubDate>
            <atom:updated>2025-12-12T07:50:27.354Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bh3urUxDr9w-N6mf" /><figcaption>Photo by <a href="https://unsplash.com/@bluestonex_apphaus?utm_source=medium&amp;utm_medium=referral">Bluestonex</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Practical insights from a year of using AI tools across iOS development, App Store pipelines, and SDK migrations.</h4><p>This article is posted as day 9 of the <a href="https://medium.com/eureka-engineering"><em>2025 Pairs Engineering Advent Calendar</em></a><em>.</em></p><p>2025 was the year I finally stopped rolling my eyes at AI demos and actually put these tools to work. Once I did, I realized there is a real gap between the hype and what is genuinely useful in day-to-day development.</p><p>I have always been a bit of a skeptic, at least until the first half of this year. But as the tools improved during the second half, I noticed that the most interesting benefits had nothing to do with the “AI will write your app” narrative. The real value came from places I did not expect.</p><h3>Background</h3><p>A few months ago, my colleagues at <a href="https://eure.jp/">Eureka</a> and I were fortunate to be given access to high-tier models and encouraged to explore what we could do with them. In only a couple of months:</p><ul><li>Our iOS repo started using automatic Pull Request code reviews from <a href="https://claude.ai/">Claude</a> and <a href="https://openai.com/codex/">Codex</a>. Many comments catch surprising issues none of us notice in the diffs.</li><li>We have relied on <a href="https://github.com/copilot">Copilot</a> to update code in the Pull Request for simple changes such as formatting, editing comments, and renaming variables.</li><li>We built a pipeline where our Marketing Team updates our App Store metadata through Google Forms. Our repo then pulls the values automatically through the <a href="https://developers.google.com/workspace/sheets/api/guides/concepts">Google Sheets</a> and <a href="https://developer.apple.com/documentation/appstoreconnectapi">App Store Connect</a> APIs. I had zero prior experience with either API, and Claude walked me through how this flow can be implemented.</li><li>We created a master list of all our App Store In-App Purchases that auto-syncs into an internal spreadsheet. This allows relevant people who need to check IAP states to do so without digging through the complex App Store Connect pages.</li><li>We automated most of our string localization workflow using the <a href="https://support.crowdin.com/developer/api/">Crowdin</a> API. I simply gave Claude the REST documentation and asked it to propose a flow, which we turned into a working pipeline.</li><li>We automated a large part of our App Store submission and release workflows. These used to require a lot of manual effort, but Claude helped turn many steps into GitHub Actions that connect cleanly with what we already had.</li><li>We reduced some tech debt by having agents assist with SDK migrations. They are not perfect, but for a large codebase like ours they provide a very useful starting point.</li></ul><p>And these examples are only from the iOS team, separate from our usual feature work. I am sure other teams inside the company have their own lists of wins.</p><h3>Instead of “Agents can do my tasks”, think “Nobody wanted to do that, maybe agents can do it”</h3><p>AI is not replacing your job¹. What it can do today is <strong>extend your reach</strong>.</p><p>This detail matters. I have seen developers try AI to write code, feel underwhelmed by the result, and then give up on the tools altogether. In my experience, it is a lot more productive if you point it at the boring parts of the job that nobody is excited to own:</p><ul><li>Generating templates for or updating documentation</li><li>Doing deep, extensive code reviews</li><li>Looking at CI pipelines and proposing cleanups and improvements</li></ul><p><strong>If you enjoy building software, then do not hand that joy over to your agent.</strong></p><p>This may sound obvious, but if you like certain parts of your work then have your agents do something else.</p><h3>“Wrong” outputs are learnable</h3><p>Model quality matters a lot, but even when an AI’s suggestions are clearly wrong, they can still offer insights that help us take a step back and reflect.</p><p>I’ll give one example. One of our tools uses Apple’s <a href="https://github.com/swiftlang/swift-syntax">SwiftSyntax</a> to parse parts of our codebase, for example to extract strings that need translation. When the SwiftSyntax SDK published a new version, I asked Claude to update our dependency, but it kept proposing edits I had asked it to avoid. I knew the old method still existed, so I was convinced it was being stubborn for no reason.</p><figure><img alt="Claude kept proposing edits I told it not to do" src="https://cdn-images-1.medium.com/max/1024/1*2FmJWIkwZxiMPq_rJ5SASw.png" /></figure><p>So I asked again, but this time with Claude’s <em>Planning Mode</em> turned on. That mode shows a step-by-step plan before it edits anything.</p><p>Once I saw the plan, I understood what it was trying to do, and I confirmed it in Xcode.</p><figure><img alt="Old method was deprecated" src="https://cdn-images-1.medium.com/max/781/1*q4BrAsiu9rZqUNd9abv3lQ.png" /></figure><p>It was reacting to a deprecation warning that I had been ignoring. In other words, it was not randomly insisting on a change, it was trying to “fix” something it saw as a problem.</p><p>Should it have explained that better up front? Maybe. But the more important lesson for me was this: <strong>when outputs look strange, understanding the reasoning can be more valuable than the answer itself</strong>. This is a healthy mindset when working with our colleagues as well.</p><p>If I had done that upgrade manually, would I have had that same confusion? Of course not. But I also would not have improved how I use the tool, or how it supports my future workload. Since then, I usually keep <em>Planning Mode</em> on, which made working with it a lot smoother.</p><p>It also made me realize that, just like people, AIs make mistakes that come from some form of misunderstanding somewhere. When we do find them, adding small rules or notes into CLAUDE.md or AGENTS.md helps anyone who uses agents after us. That includes our code-reviewing bots.</p><h3>In the end, I think our work as Software Engineers has not really changed</h3><p>Our job is to use whatever tools we have to build solid products. That part has not changed. Whether we use punchcards to build calculators or AI to build scripts, we are the ones who decide what to build, how it should behave, and how to fix it when it breaks.</p><p>AI did not remove our responsibility or our judgment. It simply gave us a way to outsource more of the repetitive work, so we can spend more time on the parts that actually feel like engineering.</p><p><em>[1]: Until AI can be legally accountable.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea6d7c2246f8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/eureka-engineering/a-skeptical-ios-developers-take-on-ai-in-2025-ea6d7c2246f8">A Skeptical iOS Developer’s Take on AI in 2025</a> was originally published in <a href="https://medium.com/eureka-engineering">Pairs Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Displaying all SwiftUI Previews in a Storybook app]]></title>
            <link>https://medium.com/eureka-engineering/displaying-all-swiftui-previews-in-a-storybook-app-1dd8e925d777?source=rss-834daea6eec5------2</link>
            <guid isPermaLink="false">https://medium.com/p/1dd8e925d777</guid>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[John Estropia]]></dc:creator>
            <pubDate>Fri, 06 Dec 2024 15:02:11 GMT</pubDate>
            <atom:updated>2024-12-06T15:02:11.579Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lcFXdzvin-NUbkH6" /><figcaption>Photo by <a href="https://unsplash.com/@kellysikkema?utm_source=medium&amp;utm_medium=referral">Kelly Sikkema</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I’m <a href="https://github.com/JohnEstropia">John Estropia</a> from Eureka’s <em>Mobile Platforms</em> team. This article is posted as the 7th entry for the <a href="https://medium.com/eureka-engineering"><strong><em>2024</em></strong> <strong><em>Pairs Engineering Advent Calendar</em></strong></a><strong><em>.</em></strong></p><h3>Background</h3><p>The UI components we build for the <a href="https://apps.apple.com/jp/app/pairs-%E3%83%9A%E3%82%A2%E3%83%BC%E3%82%BA-%E6%81%8B%E6%B4%BB-%E5%A9%9A%E6%B4%BB%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AE%E3%83%9E%E3%83%83%E3%83%81%E3%83%B3%E3%82%B0%E3%82%A2%E3%83%97%E3%83%AA/id583376064">Pairs</a> app are accessible through our internal “Storybook” catalog app. Our designers and engineers can quickly access these screens for reference.</p><figure><img alt="Screenshot of Storybook app" src="https://cdn-images-1.medium.com/max/1024/1*KFUUDcGKtGgYsQz_NnrJ-Q.png" /><figcaption>Storybook app for Pairs components</figcaption></figure><p>We’ve made this <a href="https://github.com/eure/Storybook-ios">Storybook-iOS</a> repository public for a while now so anyone can build their own UI catalog for their components as well.</p><p><a href="https://github.com/eure/Storybook-ios">GitHub - eure/Storybook-ios: UI Component previewer for UI development faster in iOS (Currently supports only UIKit)</a></p><p>If you check the <a href="https://github.com/eure/Storybook-ios?tab=readme-ov-file#advanced-usage">README</a> section of <a href="https://github.com/eure/Storybook-ios">Storybook-iOS</a>, all components need to be declared manually using Swift’s result builders:</p><pre>let myBook = Book(title: &quot;MyBook&quot;) {<br>  BookPage(title: &quot;UISwitch&quot;) {<br>    BookPreview {<br>      let button = UISwitch()<br>      button.isOn = true<br>      return button<br>    }<br>    .title(&quot;UISwitch on&quot;)<br><br>    BookPreview {<br>      let button = UISwitch()<br>      button.isOn = false<br>      return button<br>    }<br>    .title(&quot;UISwitch off&quot;)<br>  }<br>}</pre><p>The code above will result in the following display:</p><figure><img alt="Animation showing generated storybook screens from the sample code" src="https://cdn-images-1.medium.com/max/423/1*20CvyQlDTj8a2HAhQkEBTA.gif" /><figcaption>Rendered Storybook</figcaption></figure><h3>Room for Improvement</h3><p>The problem with the current approach is that we need to manually declare the Book entries for each new component we create, which is sometimes tedious and easy to forget. We already use Swift #Previews to display our components per source file. Wouldn’t it be nice if our Storybook could automatically extract #Preview declarations?</p><p>And so we had a goal:</p><blockquote><strong>To generate our Storybook from our </strong><strong>#Preview declarations and avoid having to list new components manually</strong></blockquote><figure><img alt="Diagram showing a sample Preview code with an arrow from it to an autogenerated storybook" src="https://cdn-images-1.medium.com/max/1024/1*2SyQK3H-aDqOcKpBZtbQSQ.png" /><figcaption>Goal: Autogenerated Storybook</figcaption></figure><h3>Pseudocode</h3><p>To achieve our goal, these will be the required steps that we’d need to implement:</p><blockquote>1. Parse all types in our Swift module<br>2. Find all items related to our UI components <br>3. Display those items in our Storybook</blockquote><p>We’ve already had #3 being provided by <a href="https://github.com/eure/Storybook-ios">Storybook-iOS</a>, so we’ll focus on #1 and #2.</p><h3>Early Prototypes</h3><p>We’ve had two prototypes of this feature before but both approaches were lacking.</p><h4>Prototype 1: A Swift macro that lets us write #StorybookPage similar to #Preview, but does not get rendered in Xcode’s SwiftUI Preview</h4><pre>#StorybookPage&lt;MyLabel&gt; {<br>  BookPreview { _ in<br>    MyLabel(title: &quot;Test&quot;)<br>  }<br>}</pre><p>This macro generates the following code expansion:</p><pre>enum $s4Demo0017MyBookswift_yEEFcfMX333_0_33_253A151B37A943CF87FFC6C42B582140Ll13StorybookPagefMf2_20__🤖🛠️_StorybookMagic_fMu_: BookProvider {<br>  @MainActor<br>  static var bookBody: BookPage {<br>    .init(<br>      title: _typeName(MyLabel.self),<br>      destination: {<br>        BookPreview { _ in<br>          MyLabel(title: &quot;Test&quot;)<br>        }<br>      }<br>    )<br>  }<br>}</pre><p>Note that the generated type conforms to a BookProviderprotocol. The original idea was to create a Swift macro that simulates #Preview and <em>maybe</em> make it display on Xcode’s SwiftUI Previews as well.</p><p><strong>Spoilers</strong>:<em> </em>Xcode treats the #Preview macro as a special keyword and <strong>it will not render</strong> any other view even if you generate the same code and protocol conformances that #Preview does.</p><p>But, we did successfully list all our #StorybookPagedeclarations automatically into our Storybook app.</p><p>To start explaining how this works, let’s look at step 1 again:</p><blockquote>1. Parse all types in our Swift module</blockquote><p>Apple is one of the proponents of the <a href="https://en.wikipedia.org/wiki/Mach-O">Mach-O file format</a>, and iOS apps and Swift modules also use it as their binary format. The idea is to scan for all symbols in a Swift module by parsing the module file based on the Mach-O specification, and then convert those data to Swift types we can work with, such as Swift <strong><em>protocol</em></strong>s. This format is exposed as a C API accessible from Swift from the MachO module:</p><pre>import MachO</pre><figure><img alt="Rough illustration of sections in a Mach-O header" src="https://cdn-images-1.medium.com/max/1024/1*DU70JObZN2VZagQez0iAWw.png" /><figcaption>A rough glimpse of the Mach-O binary header sections</figcaption></figure><p>Even luckier, <a href="https://derekselander.github.io/dsdump/">someone already demonstrated this parsing method long ago with Objective-C and Swift</a>, and although there are new sections in the Mach-O file header now to accommodate for new Swift features, we were able to experiment and get the results we needed from the knowledge from that article. I will not go into the details (feel free to check out the implementation details <a href="https://github.com/eure/Storybook-ios/blob/main/Sources/StorybookKit/Internals/machOLoader.swift#L50">here</a>), but the idea is that our #StorybookPagemacro wrapped the view in our BookProvider , and our Mach-O parsing was able to find all types that conformed to theBookProviderprotocol. This lets us clear step 2 as well:</p><blockquote>2. Find all items related to our UI components</blockquote><p>But as I mentioned earlier, we lost the ability to display real-time updates of our views in SwiftUI Previews.</p><h4>Prototype 2: A Swift macro #StorybookPreview that we could nest inside #Preview which made SwiftUI Previews work again</h4><pre>#Preview(&quot;Title&quot;) {<br>  #StorybookPreview&lt;MyLabel&gt; {<br>    BookPreview { _ in<br>      MyLabel(title: &quot;Test&quot;)<br>    }<br>  }<br>}</pre><p>This macro generates the following code expansion:</p><pre>#Preview(&quot;Title&quot;) {<br>  {<br>    enum $s4Demo0017MyBookswift_yEEFcfMX326_2_33_253A151B37A943CF87FFC6C42B582140Ll16StorybookPreviewfMf_20__🤖🛠️_StorybookMagic_fMu_: BookProvider {<br>     @MainActor<br>      static var bookBody: BookPage {<br>        .init(<br>          title: _typeName(MyLabel.self),<br>          destination: {<br>            BookPreview { _ in<br>              MyLabel(title: &quot;Test&quot;)<br>            }<br>          }<br>        )<br>      }<br>    }<br>    return $s4Demo0017MyBookswift_yEEFcfMX326_2_33_253A151B37A943CF87FFC6C42B582140Ll16StorybookPreviewfMf_20__🤖🛠️_StorybookMagic_fMu_.bookBody.destination<br>  }()<br>}</pre><p>Borrowing the tools we used from Prototype 1, we were able to inline the BookProviderfrom inside #Preview, and now Xcode is happy to render our SwiftUI previews again.</p><p>This works for our original goal, but we found some inconveniences around it:</p><ul><li>On a large project, Xcode kind of struggles with autocompletion when you are typing inside nested macro declarations. This means we have to type in our preview code inside #Preview first, and then insert a #StorybookPreview inside afterwards.</li><li>To use the macros in the first place, we’d need to import the module that declares the #StorybookPage and #StorybookPreview macros. This is an extra import for each file and an extra dependency that we’d need to add to all our modules that need it. And since the <a href="https://github.com/eure/Storybook-ios">Storybook-iOS</a> module is only available for our DEBUG and internal builds, that import also needs to be wrapped in #if-endif precompiler blocks:</li></ul><pre>#if canImport(StorybookKit)<br>import StorybookKit<br><br>#Preview(&quot;Title&quot;) {<br>  #StorybookPreview&lt;MyLabel&gt; {<br>    BookPreview { _ in<br>      MyLabel(title: &quot;Test&quot;)<br>    }<br>  }<br>}<br>#endif</pre><h3>Final (?) Prototype</h3><p>Now that we know how to find Swift types from modules, we’re ready to go back to the original problem:</p><blockquote><strong>To generate our Storybook from our </strong><strong>#Preview declarations and avoid having to list new components manually</strong></blockquote><p>If you try to expand a #Preview macro, you’ll find that the types generated conform to a DeveloperToolsSupport.PreviewRegistry protocol:</p><pre>#Preview {<br>  Text(&quot;My Component&quot;)<br>}</pre><pre>@available(iOS 17.0, macOS 14.0, tvOS 17.0, visionOS 1.0, watchOS 10.0, *)<br>struct $s4Demo0017MyBookswift_yEEFcfMX181_0_33_253A151B37A943CF87FFC6C42B582140Ll7PreviewfMf1_15PreviewRegistryfMu_: DeveloperToolsSupport.PreviewRegistry {<br>    static var fileID: String {<br>        &quot;Demo/MyBook.swift&quot;<br>    }<br>    static var line: Int {<br>        182<br>    }<br>    static var column: Int {<br>        1<br>    }<br><br>    static func makePreview() throws -&gt; DeveloperToolsSupport.Preview {<br>        DeveloperToolsSupport.Preview {<br>            func __b_buildView(@SwiftUI.ViewBuilder body: () -&gt; any SwiftUI.View) -&gt; any SwiftUI.View {<br>                body()<br>            }<br>            return __b_buildView {<br>              Text(&quot;My Component&quot;)<br>            }<br>        }<br>    }<br>}</pre><p>From our BookProvider experience, we know that we can find Swift protocols, including PreviewRegistry. Let’s peek into the DeveloperToolsSupport module and see what this protocol can do for us:</p><pre>@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *)<br>public protocol PreviewRegistry {<br><br>    static var fileID: String { get }<br>    static var line: Int { get }<br>    static var column: Int { get }<br><br>    @MainActor static func makePreview() throws -&gt; Preview<br>}</pre><p>That’s great, it looks like there is a static func makePreview() function we can call directly from the type without creating an instance. But wait, let’s look at what Preview looks like:</p><pre>@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *)<br>@MainActor public struct Preview {<br>}</pre><p>Uh-oh, there’s nothing exposed to the public API! Understandably, Apple wrote this for the sole purpose of the #Preview macro. But let’s not give up and try to call dump() on the Preview instance returned from themakePreview() method:</p><pre>guard let previewType = anyType as? any DeveloperToolsSupport.PreviewRegistry.Type {<br>  continue<br>}<br>let preview = try! previewType.makePreview()<br>dump(preview)</pre><pre>▿ Preview<br>  ▿ displayName : Optional&lt;String&gt;<br>    - some : &quot;Title&quot;<br>  ▿ source : DefaultPreviewSource&lt;ViewPreviewBody&gt;<br>    - contentDomain : DeveloperToolsSupport.PreviewSourceContentDomain.view<br>    ▿ contentCategory : PreviewSourceContentCategory<br>      - rawValue : &quot;SwiftUI.View&quot;<br>    - supportsOnDevicePreviews : true<br>    - supportsInteractivePreviews : true<br>    ▿ structure : Structure<br>      ▿ singlePreview : 1 element<br>        - makeBody : (Function)<br>  - traits : 0 elements</pre><p>There seems to be a makeBody function that looks promising, but long story short, the only way we can get access to this method is if we traverse it through Swift’s Mirror (reflection) API:</p><pre>guard let previewType = anyType as? any DeveloperToolsSupport.PreviewRegistry.Type {<br>  continue<br>}<br>let preview = try! previewType.makePreview()<br>let previewMirror: Mirror = .init(reflecting: preview)<br>guard<br>  let sourceMirror = previewMirror.children<br>    .first(where: { $0.label == &quot;source&quot; })<br>    .map({ Mirror.init(reflecting: $0.value) }),<br>  let structureMirror = sourceMirror.children<br>    .first(where: { $0.label == &quot;structure&quot; })<br>    .map({ Mirror.init(reflecting: $0.value) }),<br>  let previewMirror = structureMirror.children<br>    .first(where: { $0.label == &quot;singlePreview&quot; })<br>    .map({ Mirror.init(reflecting: $0.value) }),<br>  let makeBody = previewMirror.children<br>    .first(where: { $0.label == &quot;makeBody&quot; })<br>else {<br>  continue<br>}</pre><p>Let’s see what makeBody looks like from the Xcode console:</p><pre>(lldb) po type(of: makeBody.value)<br><br>@Swift.MainActor () -&gt; SwiftUI.ViewPreviewBody</pre><p>It does look like a closure, but we have no access to the SwiftUI.ViewPreviewBody type since it’s a private API. Let’s try to cast it to SwiftUI.View:</p><pre>(lldb) po makeBody.value as! @MainActor () -&gt; any SwiftUI.View<br><br>Could not cast value of type &#39;@Swift.MainActor () -&gt; SwiftUI.ViewPreviewBody&#39; (0x10a06acf8) to &#39;@Swift.MainActor () -&gt; SwiftUI.View&#39; (0x10a06ae20).</pre><p>What happens if we use unsafeBitCast and call the function directly?</p><pre>let closure = unsafeBitCast(<br>  makeBody.value,<br>  to: (@MainActor () -&gt; any SwiftUI.View).self<br>)<br>let view = closure()<br>dump(view)</pre><pre>▿ SwiftUI.Text<br>  ▿ storage: SwiftUI.Text.Storage.anyTextStorage<br>    ▿ anyTextStorage: &lt;LocalizedTextStorage: 0x0000600002139130&gt;: &quot;My Component&quot; #0<br>      - super: SwiftUI.AnyTextStorage<br>      ▿ key: SwiftUI.LocalizedStringKey<br>        - key: &quot;My Component&quot;<br>        - hasFormatting: false<br>        - arguments: 0 elements<br>      - table: nil<br>      - bundle: nil<br>  - modifiers: 0 elements</pre><p>There we go! That’s our Text preview! Since we’re only using storybooks in non-production apps, unsafeBitCast will do fine for our use. Now that we can create the SwiftUI.View instances directly from the PreviewRegistry types, it’s trivial to add it to our Storybook from here 👍</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v9RHOSGKrrLA69HynL-2bg.png" /><figcaption>#Preview components listed by modules in our Storybook</figcaption></figure><h3>Conclusion</h3><p>With this approach, we are now able to add components to our Storybook by just doing our usual #Preview creation workflow. The Mach-O introspection approach is quite powerful as it has the ability to find any public type in any module. For example, <a href="https://github.com/swiftlang/swift-testing">Swift-Testing</a> lets us write Unit Tests like so:</p><pre>@Test func helloWorld() {<br>  let greeting = &quot;Hello, world!&quot;<br>  #expect(greeting == &quot;Hello&quot;) // Expectation failed: (greeting → &quot;Hello, world!&quot;) == &quot;Hello&quot;<br>}</pre><p>And in fact, <a href="https://github.com/swiftlang/swift-testing/blob/main/Sources/_TestingInternals/Discovery.cpp#L290">Mach-O is heavily used by this framework</a> to look for unit-testable code generated by the Swift macros.</p><p>I hope you enjoyed this article as much as I did investigating the internals of #Preview. Please do check out my colleagues’ blog posts over at <a href="https://medium.com/eureka-engineering">Pairs Engineering</a>!</p><h3>Appendix: Gotchas when Introspecting #Previews</h3><ul><li>The Mach-O contains all Swift types in a module, and that means ALL of them. You need to filter the types as much as you can to prevent 10–20 seconds of blocking the main thread. For Swift #Preview, <a href="https://github.com/eure/Storybook-ios/blob/john/previewRevamp/Sources/StorybookKit/Internals/machOLoader.swift#L184">something like this</a> is enough before accessing the type’s metadata:</li></ul><pre>guard<br>  case .structType = contextDescriptor.pointee.kind(), // #Previews only generate structs<br>  contextDescriptor.nameContains(&quot;PreviewRegistry&quot;) // Generated types will have this substring<br>else {<br>  continue<br>}</pre><ul><li>In that sense, you would also need to filter which modules you want previews from, because the Mach-O header will also include those coming from 3rd party modules depending on how your dependencies are declared.</li><li>iOS 17 added support for UIViews and UIViewControllers inside #Preview blocks. But if you are using Swift 6 and <strong><em>Complete</em></strong> Concurrency settings already, you might need to give up on supporting iOS 17 for those previews because makeView and makeViewController functions for those types are compiled in the standard SwiftUI SDK as @MainActor () -&gt; UIView (and UIViewController respectively), but starting from Xcode 16.1, @MainActor in our code is now automatically force-converted by the compiler to @MainActor @Sendable, which means <a href="https://forums.swift.org/t/is-there-any-real-difference-between-mainactor-sendable-and-mainactor/72525/8">there is no way to cast the closure back to something that our code can use</a>, not even unsafeBitCast() . In our case, this was an acceptable compromise.</li></ul><pre>Could not cast value of type &#39;@Swift.MainActor () -&gt; __C.UIView&#39; to &#39;@Swift.MainActor @Sendable () -&gt; __C.UIView&#39;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1dd8e925d777" width="1" height="1" alt=""><hr><p><a href="https://medium.com/eureka-engineering/displaying-all-swiftui-previews-in-a-storybook-app-1dd8e925d777">Displaying all SwiftUI Previews in a Storybook app</a> was originally published in <a href="https://medium.com/eureka-engineering">Pairs Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Code review and Debug-friendly Programming]]></title>
            <link>https://medium.com/eureka-engineering/code-review-and-debug-friendly-programming-6956f2f42f30?source=rss-834daea6eec5------2</link>
            <guid isPermaLink="false">https://medium.com/p/6956f2f42f30</guid>
            <category><![CDATA[self-documenting-code]]></category>
            <category><![CDATA[programming-tips]]></category>
            <category><![CDATA[good-coding-practice]]></category>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[debugging]]></category>
            <dc:creator><![CDATA[John Estropia]]></dc:creator>
            <pubDate>Fri, 08 Dec 2023 22:02:04 GMT</pubDate>
            <atom:updated>2023-12-08T22:02:04.214Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nV5GhCn3oYbxQfOty76vxg.jpeg" /></figure><p>I’m <a href="https://github.com/JohnEstropia/">John</a> from Eureka’s iOS Team and this is the 9th post in <a href="https://qiita.com/advent-calendar/2023/eureka">Eureka’s 2023 Advent Calendar</a>. Check out my colleagues’ stuff as well!</p><p>As programmers, we often forget that the code we write is not only an implementation of a particular feature but also a medium of communication. Both our teammates and our future selves will be reading and working with our code for as long as it stays in the codebase. Keeping that in mind, there are several aspects of coding that we may not take seriously, but offer potential conveniences for us and our teammates during code reviews and when debugging. In this article, I’d like to introduce some perspectives that might help you adopt new ways of writing code that you may have not considered before.</p><p><em>(I’ll be using </em><em>Swift syntax for sample code below, but the concepts themselves apply to any language)</em></p><h3>Generosity with Linebreaks and Whitespaces</h3><p>This might sound irrelevant, but linebreaks do affect our workflows quite significantly.</p><h4>Linebreaks affect the usefulness of breakpoints</h4><p>Let’s say we’re debugging this code and we want to hit a breakpoint when formData has any invalid inputs:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7d0c111b2aa9c63ece6ea6132461530/href">https://medium.com/media/d7d0c111b2aa9c63ece6ea6132461530/href</a></iframe><p>You put a breakpoint at line 1, but then your breakpoint is hit every time regardless of the hasInvalidItem value. By adopting the practice of strategically inserting line breaks in control branches, we can make it easier for future debuggers without having to insert linebreaks themselves and recompile the program.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bfedfbd20a29803afdb38daa66bd2736/href">https://medium.com/media/bfedfbd20a29803afdb38daa66bd2736/href</a></iframe><h4>Linebreaks and whitespaces make code reviews easier</h4><p>Let’s say we have a multi-parameter function and we recently added a new parameter in a new Pull-Request. If we’re conservative with linebreaks, this is how the diffs would look like in Github’s “Split” and “Unified” views:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gxQQbf9AF2rY6ML2DR8hoA.png" /><figcaption>No linebreaks in Split mode</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Whg4yP0GXkihKu295ko0HQ.png" /><figcaption>No linebreaks in Unified mode</figcaption></figure><p>Notice how the red and green highlighting encompass the whole of lines 2 and 3, and how <strong>our eyes need to move both horizontally and vertically</strong> to compare each item changes. GitHub helps emphasize the affected variables by displaying even stronger red and green highlights, but take a look at how much noise we can remove from the diff if we were generous with linebreaks in the first place:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jPWslffVBpJuhH7JdMObZQ.png" /><figcaption>With linebreaks in Split mode</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3PFp9AIeg9qK-tBcPG0beg.png" /><figcaption>With linebreaks in Unified mode</figcaption></figure><p>Now <strong>our eyes just need to move in one direction</strong> to make the necessary comparisons.</p><p>As an added benefit, <strong>code reviewers can now make pinpoint comments on each line</strong> as needed.</p><h3>Vigilance with Spelling</h3><p>We’ve all seen spelling typos. As a code reviewer, they’re quite easy to let through as we mostly review code as “programs” and not as linguistic “words”. But minor spelling mistakes do break workflows that could have been easier without them:</p><h4>Spelling typos complicate searching</h4><p>As code maintainers, we often search substrings in code for different reasons:</p><ul><li>when we’re debugging an issue and we’re looking for occurrences of a specific term</li><li>when we need to do a full codebase renaming because of a refactoring/rebranding</li></ul><p>These extend to both code and filenames. Doing a grepand realizing long after the fact that you missed several spelling variations can be disruptive. What’s worse is that it’s hard to find all possible combinations of misspellings, so it’s better to clear them before the code gets merged into the repository.</p><blockquote>🔍 maintenance<br>🔍 maintenence<br>🔍 maintainance</blockquote><p>Sometimes though, there are also words that do have different accepted spellings.</p><blockquote>🔍 cancellation<br>🔍 cancelation</blockquote><p>In these cases, it would be ideal to have a standard agreed upon by the team. Find the most commonly accepted spelling used in the domain. For example, iOS platforms use “<a href="https://developer.apple.com/documentation/uikit/uicolor">color</a>” instead of “colour”, therefore we can align ourselves to US English spelling instead of the UK counterpart.</p><h4>Spelling and capitalization typos can become maintenance nightmares</h4><p>Sometimes we use hardcoded strings in certain places and obviously, misspellings would break expected behavior in that program.</p><pre>requestParameters[&quot;comunity_id&quot;] = communityID</pre><p>Now this is obviously a mistake and is easily discovered through testing, but what I want to talk about is the reverse case: <strong>when wrong spelling accidentally becomes the enforced spelling</strong>.</p><p>One notorious example of this is how the HTTP request header <a href="https://en.wikipedia.org/wiki/HTTP_referer">Referer</a>(a misspelling of “Referrer“) had unfortunately been declared part of the HTTP protocol, and now everyone who needs to work with it has to be aware of how it should be spelled vs. some of its related terms like <a href="https://www.w3.org/TR/referrer-policy/">Referrer-Policy</a>(in DOM) or <a href="https://www.w3.org/TR/2017/WD-html52-20170228/links.html#link-type-noreferrer">rel=noreferrer</a> (in HTML5).</p><p>Any schema specification that establishes a “contract” is at risk of such issues. For example:</p><ul><li>Client-side database table or column names would cause corrupted data in older versions if we suddenly rename them in future updates.</li><li>Backend would still have to support compatibility with old request/response formats if any request parameter names, response JSON keys, or resource identifiers need to be renamed</li></ul><p>Once typos like these reach your end-users, you’ll be forced to either live with them forever or plan a costly migration to fix the issue.</p><blockquote>⚠️ Column name “community_id” not found. Did you mean “comunity_id”?</blockquote><h3>Self-Documenting Code</h3><p>The topic itself is broad, and I’m sure most of you know some of the basics:</p><ul><li>Using descriptive variable/constant/function/file names that describe “what”</li><li>Using source code comments only to explain “why” a particular code is written that way</li><li>etc., etc., etc.</li></ul><p>What I’d like to talk about today are practices that offer extra context about our code.</p><h4>Communicating expectations</h4><p>If you read that title and thought “Is it Unit Testing?” then good for you! Yes, <strong>Unit Tests are definitions of how specific parts of code are expected to behave.</strong> But the thing about Unit Tests is that they are usually written somewhere far from the piece of code it is testing, often in a separate module that is compiled separately from the target code. This is why we have assert() functions in most modern programming languages as they allow inline declaration of assumptions/expectations at very specific lines in code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df7bd632e0cbb997b8c86a96b0963bd2/href">https://medium.com/media/df7bd632e0cbb997b8c86a96b0963bd2/href</a></iframe><p>One particular benefit of assert() over Unit Tests is that <strong>they are also meant to discover unexpected behavior</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec760e1dfc2fb2a8e1c324216554f091/href">https://medium.com/media/ec760e1dfc2fb2a8e1c324216554f091/href</a></iframe><h4>Enforcing expectations through type-safety</h4><p>Communicating expectations (and unexpectations) is one thing, but wouldn’t it be perfect if we could actually make it impossible to provide values other than the expected ones? Let’s say we have this function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2a32b576ef62c32be5d9a1017700286/href">https://medium.com/media/f2a32b576ef62c32be5d9a1017700286/href</a></iframe><p>Note that some of these parameters use the same Stringtype. From the caller’s side, it’s completely possible to make this mistake:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d508c687a3290b5ebbc80d679309f77/href">https://medium.com/media/9d508c687a3290b5ebbc80d679309f77/href</a></iframe><p>To make it short, this would be the ideal form of our function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98ccb1af180c649f66a0460c69813201/href">https://medium.com/media/98ccb1af180c649f66a0460c69813201/href</a></iframe><p>Now that they are declared as different types, we can now enforce each parameter to have the correct values by limiting how these types are initialized depending on what we expect of them. Let’s start with the type-safe IDs:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3dc59b88c33dfa69270c1e5ee9f1607d/href">https://medium.com/media/3dc59b88c33dfa69270c1e5ee9f1607d/href</a></iframe><p><strong>We can limit where the IDs can be created so that nobody can create them by accident</strong>. In this case, the FacebookID and TwitterIDcan only be created from within their dedicated methods, and they cannot be used interchangeably afterward.</p><p>Next, we can also limit parameters to values that are already verified to be correct. Let’s take a look at how we’d declare the rest of the parameter types:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/daa61be4d91e76b9611c9a3272b3f7b3/href">https://medium.com/media/daa61be4d91e76b9611c9a3272b3f7b3/href</a></iframe><p>So from now on, to create these values we’d have to handle the errors thrown by the initializers, which would be useful in tandem with UI controls that display error labels, play specific sounds, or perform haptic feedback. <strong>After these values are created, we’d never have to check their validity again, which lets us greatly reduce Unit Tests and</strong><strong>assert() calls</strong>, and potentially make future debugging a breeze.</p><h3>Conclusion</h3><p>There’s one important thing about some points I shared above: They are relatively awkward for us to point out during code reviews because they are quite trivial and there is some embarrassment factor that nobody wants to inflict onto teammates. So the takeaway here is that <strong>these are practices we should enforce mostly on ourselves</strong>. These guidelines should never be the cause of long arguments during code reviews, but the benefits they offer to ease future work are worth the extra care in our own code. The good news is that they are quite easy to get right with the help of existing utilities offered by IDEs and tools such as Linters and Code Formatters.</p><p>Did you find these tips interesting? Do you have your own tips for improving code reviews and debugging workflows? Feel free to share them in the comments.</p><p><a href="https://qiita.com/advent-calendar/2023/eureka">Eureka’s 2023 Advent Calendar</a> continues, so stay tuned and enjoy the upcoming articles! Or check out the rest of our <a href="https://medium.com/eureka-engineering">Engineering Blogs</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6956f2f42f30" width="1" height="1" alt=""><hr><p><a href="https://medium.com/eureka-engineering/code-review-and-debug-friendly-programming-6956f2f42f30">Code review and Debug-friendly Programming</a> was originally published in <a href="https://medium.com/eureka-engineering">Pairs Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[You don’t need SwiftUI to enjoy its layout syntax]]></title>
            <link>https://medium.com/eureka-engineering/you-dont-need-swiftui-to-enjoy-its-layout-syntax-7752fc45caef?source=rss-834daea6eec5------2</link>
            <guid isPermaLink="false">https://medium.com/p/7752fc45caef</guid>
            <category><![CDATA[texture]]></category>
            <category><![CDATA[uikit]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[John Estropia]]></dc:creator>
            <pubDate>Thu, 02 Dec 2021 03:14:44 GMT</pubDate>
            <atom:updated>2021-12-06T15:12:50.615Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*geyXiX58M9BI_V83Ano9zg.png" /></figure><p><em>This is the December 2 article for </em><a href="https://qiita.com/advent-calendar/2021/eureka"><em>Eureka’s 2021 Advent Calendar</em></a><em>.</em></p><p>I’ll be tackling one of the controversial topics that are dividing iOS/macOS developers these days, mainly the SwiftUI vs. UIKit mindset that is trending in the industry. Hopefully, I can provide some insights that will <strong><em>reconcile</em></strong> both sides on the topic.</p><p>In Eureka we cannot use SwiftUI yet, but I maintain SwiftUI utilities for my open-source library <a href="https://github.com/JohnEstropia/CoreStore">CoreStore</a> and wrote one of my hobby apps in pure SwiftUI initially (though I rewrote it in <a href="https://github.com/texturegroup/texture">Texture</a> for performance and maintenance reasons). My observations and opinions on SwiftUI are based on my own experience using it.</p><h3>The reality of SwiftUI</h3><p>First, let’s take a look at SwiftUI and the paradigm shift that it brought to Apple platforms.</p><h4>Why SwiftUI?</h4><p>One of the biggest selling points of SwiftUI is the <em>ease of app development</em>. And I think no one would argue against how easy it is to bootstrap a new app from scratch with SwiftUI. There’s a lot to unpack on why that is, but I personally think it’s two main factors: the <strong>layout syntax</strong> and the <strong>out-of-the-box features</strong>.</p><p><strong>Layout Syntax</strong></p><p>This is the biggest draw for all iOS/macOS developers. Even <a href="https://developer.apple.com/xcode/swiftui/">Apple’s SwiftUI intro homepage</a> puts <strong>Declarative syntax</strong> as its first talking point.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c2eae9333a4672d1872bcbbe9692eb1/href">https://medium.com/media/9c2eae9333a4672d1872bcbbe9692eb1/href</a></iframe><p>If you haven’t realized yet, this is almost the same structure as <a href="https://developer.android.com/jetpack/compose">Jetpack Compose</a> on Android. I think declarative UI will be the preferred DSL within programming languages in the near future.</p><p><strong>Out-of-the-box Features</strong></p><p>With SwiftUI, Apple took the effort to provide automatic support for common features that most apps take for granted: <strong>animations</strong>, <strong>accessibility</strong>, and <strong>multi-platform support</strong>, among others.</p><p>For example, SwiftUI’s <strong><em>Button</em></strong> control can be used as-is whether you are writing for iOS, macOS, iPadOS, watchOS, or tvOS. For each platform, the corresponding “button” implementation would be used instead, complete with the relevant design, animations, and accessibility features present for buttons in that platform.</p><h4>So why not SwiftUI?</h4><p>Here are the biggest drawbacks I found with SwiftUI:</p><p><strong>Two-way Bindings</strong></p><p>On paper, a two-way binding would be better to enforce synchronization of the model and the view, but counterintuitively this causes a lot of UI issues because of <em>necessary</em> delays like animations, network latency, and user perception adjustments. In short, between those periods of delay, the source of truth for the <strong><em>Binding</em></strong> is torn between the model and the view. This is still one of the surprising architectural decisions I find in SwiftUI since it was first released because <a href="https://facebook.github.io/flux/docs/in-depth-overview/#:~:text=A%20unidirectional%20data%20flow%20is,and%20an%20identifying%20type%20property.">one-way binding (unidirectional data flow) is the standard in other state-driven architectures like Flux</a>, <a href="https://www.tutorialspoint.com/redux/redux_data_flow.htm">Redux</a>, <a href="https://developer.android.com/jetpack/compose/architecture">Jetpack Compose</a>, etc.</p><p><a href="https://developer.apple.com/forums/thread/127218">This is a common issue with input controls like <strong><em>Picker</em></strong>s</a> and <strong><em>Slider</em></strong>s. When the user fiddles with a control, the <strong><em>Binding</em></strong> updates the model with the control’s new value, which triggers a re-render on the SwiftUI view tree, <em>which then unnecessarily resets the control</em>. On a <strong><em>Picker</em></strong>, this means any rolling animation is cancelled and will cause flickers, and on a <strong><em>Slider</em></strong> this may move the value back to an older value until the user moves their finger again.</p><p>Now obviously, there are workarounds for these but it just goes to show that bindings are unnecessarily more complex than expected.</p><p><strong>Nondeterministic Layout Timing</strong></p><p>One other well-known quirk in SwiftUI <strong><em>View</em></strong>s is the frequency of evaluation of the <strong><em>View</em></strong>’s <strong><em>body</em></strong>. An update to a <strong><em>@State</em></strong> or <strong><em>@ObservableObject</em></strong> may trigger a reevaluation of the whole view tree in some cases, even if that value changes nothing in the visual appearance.</p><p>For example, if data is deleted which causes a screen to be dismissed, the label that displayed that data may disappear (flicker) even before the dismiss animation completes. It’s a tiny difference but it makes your app look clunky. With UIKit, we call <strong><em>setNeedsLayout()</em></strong> or explicitly change <strong><em>NSLayoutConstraint</em></strong>s to trigger layout updates, but with SwiftUI we have to be aware of how the declarative syntax will translate into “update triggers”. This makes it a lot harder to debug, and while <a href="https://twitter.com/JohnEstropia/status/1439394581422895104?s=20">logging tools exist for SwiftUI</a>, following breakpoints is more intuitive during debugging.</p><p><strong>Closed-source</strong></p><p>And finally, the most unfortunate fact is that SwiftUI is closed-source (instead of say, maintained through a branch of <a href="https://www.swift.org/community/#swift-evolution">Swift Evolution</a>), which then caused SwiftUI’s implementation to become tied to iOS versions. This means the behavior of your SwiftUI app is different between iOS 13, 14, and 15 (as of 2021). This completely defeats the <strong>multi-platform support</strong> we mentioned earlier because now your code has branching logic for different iOS versions instead of different platforms.</p><p>And then these differences between SwiftUI versions are not trivial either. Each new iteration added features that would make outsiders think: <em>“Wait, you never had that before?”<br></em> To give you an idea, the first versions of SwiftUI never had a native way to:</p><ul><li>display badge numbers in <strong><em>TabItem</em></strong>s</li><li>change <strong><em>List</em></strong> separator colors</li><li>display multiline <strong><em>TextField</em></strong>s</li><li>display <strong><em>NSAttributedString</em></strong>s</li><li>add pull-to-refresh to <strong><em>List</em></strong>s</li><li>show maps</li><li>show videos</li><li><em>etc.</em></li></ul><p>And yes, I know these were all doable in SwiftUI by writing your own <strong><em>UIViewControllerRepresentable</em></strong>, but those same components were already how you’d have done them in UIKit. These components would have been the pet projects of library developers, but because of the iOS version fragmentation issue, it became harder for the community to maintain 3rd-party controls.</p><p>Funnily enough, the most popular 3rd-party SwiftUI library just proved how much the closed-source nature of SwiftUI became a burden. <a href="https://github.com/siteline/SwiftUI-Introspect">SwiftUI-Introspect: Introspect underlying UIKit components from SwiftUI</a>.</p><h3>Our previous layout system</h3><p>Now that we’ve explored the pros and cons of using SwiftUI, I will now introduce the layout frameworks that we use in Eureka’s apps and later show you how we have incorporated some of SwiftUI’s paradigms into our existing apps.</p><h4><a href="https://github.com/texturegroup/texture">Texture</a></h4><p>We’ve been using <a href="https://github.com/texturegroup/texture">Texture (former AsyncDisplayKit)</a> for several years now, and we still vouch for its performance wins in high-traffic UI. It’s also one of the earliest implementations of declarative layout and stack-based layout on iOS, both paradigms we’d eventually see in SwiftUI.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c70dee6b61164b94bfaa2a270cf3ce0/href">https://medium.com/media/6c70dee6b61164b94bfaa2a270cf3ce0/href</a></iframe><p>It’s a bit verbose, but notice how close the structure is compared to our previous SwiftUI sample code. It’s also leagues better than how we’d write the same layout using traditional <strong><em>NSLayoutConstraint</em></strong>s. While Texture has its own <a href="https://texturegroup.org/docs/layout2-web-flexbox-differences.html">layout mechanism based on Flexbox</a>, it simply manages underlying <strong><em>UIView</em></strong>s and <strong><em>CALayer</em></strong>s so it’s easy for existing iOS projects to incrementally migrate to Texture’s architecture. Unlike SwiftUI, we can call <strong><em>setNeedsLayout()</em></strong> precisely at the point when we’re ready to let the layout recompute itself.</p><p>But, it left room for more improvement. Although it’s very intuitive, a simple tweak such as adding a <em>padding</em> would mean having to move the existing tree into a parent <strong><em>ASInsetLayoutSpec</em></strong> container. So something like this in SwiftUI:</p><blockquote>contents.padding(10)</blockquote><p>would translate to this in Texture:</p><blockquote>ASInsetLayoutSpec(<br> insets: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10),<br> child: contents<br>)</blockquote><h4><a href="https://github.com/nakiostudio/EasyPeasy">EasyPeasy</a></h4><p>For less-demanding screens where standard UIKit components are simpler, we use <a href="https://github.com/nakiostudio/EasyPeasy">EasyPeasy</a> to simplify our AutoLayout configuration. (EasyPeasy code at the bottom part:)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f66e1f04876cf2c0cb1d0730d849112e/href">https://medium.com/media/f66e1f04876cf2c0cb1d0730d849112e/href</a></iframe><p>This code would be a lot bigger if we create layout constraints using traditional <strong><em>NSLayoutConstraint</em></strong> initializers.</p><p>Still, our declarative code was only just the constraints setup code. We’ve looked for possible solutions that would let us write more declarative code using our <strong><em>UIView</em></strong>s but never found a promising candidate.</p><h3>The power of Result Builders</h3><p>As with Eureka’s iOS engineering culture, features we want that we could not find anywhere else, we write our own: <a href="https://github.com/JohnEstropia/CoreStore">CoreStore</a>, <a href="https://github.com/muukii/JAYSON">JAYSON</a>, <a href="https://github.com/eure/AssetsPicker">MosaiqueAssetsPicker</a>, <a href="https://github.com/muukii/NextGrowingTextView">NextGrowingTextView</a>, <a href="https://github.com/muukii/Rideau">Rideau</a>, <a href="https://github.com/muukii/StackScrollView">StackScrollView</a>, <a href="https://github.com/VergeGroup/Verge">Verge</a>, and more.</p><p>And most relevant to this article, <a href="https://github.com/TextureCommunity/TextureSwiftSupport">TextureSwiftSupport</a> and <a href="https://github.com/muukii/MondrianLayout/">MondrianLayout</a>, which utilize <a href="https://github.com/apple/swift-evolution/blob/main/proposals/0289-result-builders.md">Swift’s Result Builders</a> feature to provide the same DSL as SwiftUI, all while still taking advantage of Texture and UIKit.</p><ul><li><a href="https://github.com/TextureCommunity/TextureSwiftSupport">GitHub - TextureCommunity/TextureSwiftSupport: A library that gains Texture(AsyncDisplayKit) more power in Swift.</a></li><li><a href="https://github.com/muukii/MondrianLayout/">GitHub - muukii/MondrianLayout: 🏗 A way to building layouts faster in AutoLayout like SwiftUI - powered by Result Builders</a></li></ul><h4><a href="https://github.com/TextureCommunity/TextureSwiftSupport">TextureSwiftSupport</a></h4><p>Our colleague <a href="https://twitter.com/muukii_app">Hiroshi Kimura</a> was quite the genius writing this library. With <a href="https://github.com/TextureCommunity/TextureSwiftSupport">TextureSwiftSupport</a>, our previous sample code becomes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fd88d053b639cce3bfdcb45578dd039/href">https://medium.com/media/3fd88d053b639cce3bfdcb45578dd039/href</a></iframe><p>We have migrated most of our Texture code to use this result builder syntax, and it is the most satisfying refactoring I’ve done in a while. Code reviews are super easy, and with the ability to use <strong><em>if-else</em></strong> and <strong><em>switch-case</em></strong> blocks for conditional layouts, updating an existing UI component is a lot safer because small changes have minimal effect on the layout code.</p><p>As added bonus, TextureSwiftSupport also provides two container types:</p><blockquote>class NodeView&lt;T: ASDisplayNode&gt;: UIView</blockquote><p>and</p><blockquote>class ViewNode&lt;T: UIView&gt;: ASDisplayNode</blockquote><p>which let us mix and match Texture nodes and UIKit views together depending on our needs.</p><h4><a href="https://github.com/muukii/MondrianLayout/">MondrianLayout</a></h4><p>But <a href="https://twitter.com/muukii_app">Hiroshi</a> didn’t stop there. This year we’d exchange feedbacks while we convert our AutoLayout code to use his new <a href="https://github.com/muukii/MondrianLayout/">MondrianLayout</a> library. Converting our previous EasyPeasy code, with MondrianLayout our sample code becomes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc45d4fd4481ee2d179b07a4d4e5ad80/href">https://medium.com/media/cc45d4fd4481ee2d179b07a4d4e5ad80/href</a></iframe><p>Now we have all the tools for a fully-declarative UI layout.</p><h3>Conclusion: Getting both the elegance of Result Builder layouts and the power of traditional iOS components</h3><p>It was a great journey to be able to find and build tools that would let us write fully declarative UI, without getting locked into a relatively restrictive paradigm like SwiftUI. While others <a href="https://twitter.com/JohnEstropia/status/1447822326087630848?s=20">spend time improving performance</a> or <a href="https://twitter.com/JohnEstropia/status/1451387780949438467?s=20">hack around missing SwiftUI functionality</a>, we stuck with our battle-tested frameworks and made new tools along the way to instead take advantage of what’s most appealing in SwiftUI: its declarative layout syntax using Result Builders.</p><p>If I inspired you to try out <a href="https://github.com/TextureCommunity/TextureSwiftSupport">TextureSwiftSupport</a> and <a href="https://github.com/muukii/MondrianLayout/">MondrianLayout</a> or have questions about them, feel free to post a comment below!</p><p>And that concludes my Advent Calendar topic this year. Enjoy the rest of <a href="https://medium.com/eureka-engineering">Eureka’s engineering blogs</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7752fc45caef" width="1" height="1" alt=""><hr><p><a href="https://medium.com/eureka-engineering/you-dont-need-swiftui-to-enjoy-its-layout-syntax-7752fc45caef">You don’t need SwiftUI to enjoy its layout syntax</a> was originally published in <a href="https://medium.com/eureka-engineering">Pairs Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>