<?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 Emilio Arvonio on Medium]]></title>
        <description><![CDATA[Stories by Emilio Arvonio on Medium]]></description>
        <link>https://medium.com/@emilioarvonio?source=rss-76e1571868f3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cFEQMBVj_cOSz8MIDlAwPg.jpeg</url>
            <title>Stories by Emilio Arvonio on Medium</title>
            <link>https://medium.com/@emilioarvonio?source=rss-76e1571868f3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 23:03:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@emilioarvonio/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[WWDC 2025, One Year Later: What Actually Made It Into Production (and What Didn’t)]]></title>
            <link>https://medium.com/@emilioarvonio/wwdc-2025-ios-production-retrospective-059f9bb9d1bc?source=rss-76e1571868f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/059f9bb9d1bc</guid>
            <category><![CDATA[wwdc]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[ios-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Emilio Arvonio]]></dc:creator>
            <pubDate>Sat, 06 Jun 2026 14:51:16 GMT</pubDate>
            <atom:updated>2026-06-06T14:51:16.113Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="WWDC 2025 retrospective cover — what Apple announcements made it into production for a senior iOS engineer" src="https://cdn-images-1.medium.com/max/1024/1*fwmdbottneo5uQT58aauLw.png" /></figure><h4>A senior iOS engineer’s honest look at the gap between keynote demos and enterprise reality — across Liquid Glass, Foundation Models, and AI tooling.</h4><p>Hey Devs!</p><p>In a few days Apple opens WWDC 2026, and we’ll get the usual wave of announcements, demos, and “this changes everything” energy. I genuinely love that week. But before I get swept up in it — and I will — I want to do something I find more useful than guessing what’s next: look back honestly at last year.</p><p>WWDC 2025 gave us Liquid Glass, on-device Foundation Models, and an AI assistant built right into Xcode. A full year of hype. So here’s the question I think is worth asking before the next round kicks off: of everything that got us excited in June 2025, what <em>actually</em> made it into production?</p><p>A bit of context on where I’m standing. I work on a 9-app ecosystem used by millions of users — not a greenfield side project, but a real, large, cross-platform codebase with a client, a minimum iOS version that isn’t the latest, and an Android counterpart that has to stay in sync. From that seat, the distance between a keynote demo and a shipped feature is often huge. Here’s what that distance actually looked like across three of last year’s headline announcements — and the lessons I’m taking with me into WWDC 2026.</p><h3><strong>Liquid Glass: we tested it, then turned it off</strong></h3><p>Liquid Glass was <em>the</em> announcement of WWDC 2025 — Apple’s broadest visual redesign in years, translucent surfaces and fluid transitions everywhere.</p><p>And we did give it a real shot. We rolled it out in a TestFlight build, adapting some of our custom components — the bar buttons, the tab items in the bottom bar — to look as native as possible under the new design language.</p><p>Then we turned it off.</p><p>Here’s why. Our apps are designed to look consistent across iOS and Android. That’s a product requirement, not a preference I get to argue with. When our designers worked on the new UI for several components, Liquid Glass simply didn’t fit: the bottom bar floating and lifting as if it were dodging the content clashed with the look and feel we were building toward. So the client made the call — hide Liquid Glass, ride out Apple’s one-year grace period instead.</p><p>But the part worth sharing isn’t the decision. It’s what testing Liquid Glass <em>revealed</em> about the cost we’d been quietly carrying all along.</p><p>Take our navigation bar. It’s heavily customized, and its appearance depends on context — and often on what the backend sends us. In some pages it has a blur, in others it’s transparent, in others solid black; in some it shows a logo next to the back button, in others it doesn’t. The day we dropped Liquid Glass into that, every combination reacted differently. The logo-next-to-back looked terrible. The buttons looked great on the black nav bar but disappeared against the blur. So we had to map <em>every possible combination</em> and decide what the final effect should be for each one. That single exercise took us around two weeks.</p><p>That’s the real lesson, and it’s one I’d write on a wall:</p><blockquote>Heavy UI customization is a recurring tax, not a one-time cost.</blockquote><p>Every custom component has to be re-checked on every Xcode update to make sure a new Swift version didn’t break it — visually or functionally. And the more your components react to dynamic backend data, the more edge cases explode the moment Apple changes the rendering underneath you. We hit the exact same wall again when iPad introduced the side/top bottom bar — we had to suppress the behavior with a workaround that could break on any future Swift update. That workaround is debt with a timer on it.</p><p>So where’s the line? After living through this, here’s the rule I now apply: <strong>customize the views and the page content freely — that’s where your product’s identity lives — but keep the platform chrome as native as you can.</strong> The bottom bar, the navigation bar, switches, sliders, progress bars: leave them close to default. Yes, the look and feel should be recognizable and consistent across platforms. But never forget that users are trained on distinct components and specific gestures on both Android and iOS, and that muscle memory is part of your UI whether you designed for it or not. The deeper you customize the chrome, the more you’re signing up to maintain Apple’s job for them, forever.</p><figure><img alt="Diagram showing where to use custom UI components versus native iOS components when adopting Liquid Glass" src="https://cdn-images-1.medium.com/max/1024/1*SwoWgaDQnuozlcdWXDPr6Q.png" /></figure><h3>Foundation Models: fascinating, and not yet for us</h3><p>This is the one I was most personally excited about. Apple’s on-device Foundation Models — generative AI running locally, with tool calling, stateful sessions, guided generation. Right up my alley.</p><p>So I didn’t just read about it. I built a proof of concept using the Tool protocol to make API calls that enriched the model’s responses. I ran tests in multiple languages, checking how the model interpreted user input, what came back from the APIs, and how the final result was presented. I even tried wiring up App Intents for Visual Intelligence.</p><p>That last one is a perfect little story of theory meeting reality. To use Visual Intelligence, the backend would need to expose a method that takes an image as input and returns a structured response based on it — which meant asking the client to build an image-recognition system <em>and</em> structure their data so it could be matched against those images. A heavy backend lift. And the moment that killed the proposal wasn’t technical: it was realizing how little Visual Intelligence is actually used by iPhone owners today. Apple’s AI features shipped last year are noticeably behind the competition, so adoption is low. That didn’t strengthen our pitch — it underlined that the effort to build the whole thing wouldn’t be rewarded.</p><p>That experience handed me a decision framework I now use for <em>any</em> platform-exclusive technology, not just AI. Before adopting one, I run it through three questions:</p><ol><li><strong>Is there cross-platform parity?</strong> If I can’t ship an equivalent on Android, the feature breaks our consistency requirement on day one.</li><li><strong>Does the minimum OS version make it marginal?</strong> Most of our apps support iOS 15 as a baseline. Foundation Models need far more recent versions, so any integration would reach only a slice of our users — pushing it straight into non-core territory.</li><li><strong>Is it core or accessory?</strong> I define a feature as <em>core</em> if it’s fundamental to the client’s business. For a flagship streaming app, the core is watching films, series, and live TV — the whole app exists for that. A clever AI summary feature reachable by a fraction of users, with no Android twin, is by definition not core. And you don’t spend a heavy backend effort on accessory features.</li></ol><figure><img alt="Decision framework flowchart for adopting platform-exclusive iOS features — cross-platform parity, minimum OS version, core vs accessory" src="https://cdn-images-1.medium.com/max/1024/1*rOp4o8a-LYwIBrqnCfD-kg.png" /></figure><p>The first question is the one that matters most, and it’s worth stating plainly:</p><blockquote>A feature that exists on only one platform isn’t a feature — it’s a divergence you’ll pay for later.</blockquote><p>To be clear, this isn’t “Foundation Models are useless.” In the right place they’d be excellent: summarizing a topic, rebuilding a recipe from a list of ingredients, generating a travel itinerary, extracting categories from free-form user input. In a focused utility app built around one of those functions, on-device generative AI could be the whole product. But in a cross-platform super-app with an iOS 15 floor, the constraints simply outweighed the payoff last year. I’m genuinely hoping WWDC 2026 moves this far enough forward that the math changes.</p><h3>Xcode 26’s AI Assistant vs. Claude Code: I picked the CLI</h3><p>Apple also brought AI right into Xcode 26 — inline edits, code generation, an assistant living inside the IDE.</p><p>I tried it. We didn’t get along.</p><p>For inline edits, it didn’t reliably propose usable code, or code that matched our app’s existing style. For generating files and boilerplate, it was slow enough that I often spent more time instructing it than I’d have spent just writing the thing myself. And there’s a compounding problem: Xcode is <em>already</em> very slow on large projects that lean on local SPM packages, XIBs, and Storyboards. Now add an AI layer that has to read through all those files on top of that. You can imagine.</p><p>So my setup is deliberate: I use Claude Code through the CLI, and I keep Xcode only for running the app. And the reason it works comes down to one thing I care about more than any single feature:</p><blockquote>Controllable context beats convenient context.</blockquote><p>Here’s what I mean, concretely. If you keep a single big .md instruction file, your context is heavy from the very first prompt — the model carries all of it, all the time. Instead, I give each module its own .md and keep the project-level file lean. Now the AI pulls in a module&#39;s details only when it&#39;s actually working in that module, so the context stays light and relevant instead of bloated. That&#39;s a structural advantage the IDE assistant doesn&#39;t give me: I decide <em>what</em> the model sees and <em>when</em>.</p><p>The hooks are the other half. I use them to run checks after file edits — linting, structural verification, adherence to our code style — or to outright block a change that would violate a design pattern or principle the codebase relies on. All of it dynamic, all of it managed inside Claude Code. That’s not autocomplete. That’s a workflow I shape.</p><p>This isn’t me being anti-Apple, and I want to be fair: there’s a clear case for the built-in assistant. I’d reach for it when I can’t use the CLI at all — for instance, when a client’s contract restricts which AI tools I’m allowed to use during development. On a small project, or for a quick isolated fix, the convenience of the integrated assistant might genuinely win. But on a big, slow, heavily-customized codebase, the ability to control context is worth more than the convenience of having AI in the editor. For me, the CLI wins on exactly the projects where it matters most.</p><h3>The pattern underneath</h3><p>Step back from the three stories and they rhyme. Every headline announcement from WWDC 2025 ran into the same three walls when it met my actual work — in no particular order, because they all hit hard:</p><ol><li><strong>Cross-platform parity</strong> — if Android can’t do it too, it usually can’t ship.</li><li><strong>Minimum OS version</strong> — the newest APIs reach only a fraction of a real user base for years.</li><li><strong>Large, heavily-customized codebases</strong> — every customization is a recurring tax, and every migration is a cost, not a checkbox.</li></ol><p>None of this is a complaint about Apple. The demos are real, the technology is good. But there’s a permanent gap between what earns a standing ovation in the keynote hall and what survives contact with a production app that has a client, an Android twin, and an iOS 15 floor. Deciding what to adopt now, what to defer, and what to skip entirely — that’s honestly most of the job at a senior level.</p><p>So as WWDC 2026 kicks off, that’s the lens I’ll be watching through. Not “what’s exciting?” — almost everything will be. But “what could actually make it into production this time?” That’s the harder, more useful question.</p><p>I’d love to hear how you navigate the same gap. If you work on large or cross-platform apps: what made it into production from WWDC 2025 — and what’s still sitting in a branch somewhere, waiting for the constraints to change? Drop a comment, I read them all. 🚀</p><p><em>If this resonated, I write about iOS engineering at scale, modular architecture, and AI-native development workflows — plus the occasional Tricks | Tips piece you can save for later. Always happy to connect.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=059f9bb9d1bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tricks | Tips: Parallax Effect in SwiftUI with Metal]]></title>
            <link>https://medium.com/@emilioarvonio/parallax-effect-in-swiftui-with-metal-3b8c6744480b?source=rss-76e1571868f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b8c6744480b</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[tips-and-tricks]]></category>
            <category><![CDATA[metal]]></category>
            <category><![CDATA[parallax]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Emilio Arvonio]]></dc:creator>
            <pubDate>Tue, 15 Jul 2025 11:22:21 GMT</pubDate>
            <atom:updated>2025-07-16T11:55:41.290Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FYXbdoA_r8Y_sgd-txBJ7w.png" /></figure><p>Hey Devs!</p><p>I was exploring fun ways to add a cool effect to some images in my project, and while I was browsing for ideas, I discovered Metal.</p><p>Have you ever tried creating a <strong>Parallax Effect</strong> with <em>Metal</em> in your SwiftUI Apps? Let’s explore <em>how</em> simple it can be to achieve in just 5 minutes!</p><h3>Why Metal?</h3><p>With <em>Metal,</em> we can easily create functions that manipulate our views and images on a pixel-by-pixel basis. These powerful operations are performed on the GPU, making them highly optimized for performance.</p><p>First of all, we need to create a <em>Metal</em> file. To do that, press CMD+N in Xcode on your project’s folder, and you will see this window:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5hl3zbgmrDrV5PCoGgaw6Q.png" /></figure><p>Click on <em>Metal File </em>and name it as you prefer. At this point, <em>YourName.metal </em>file will be added to your project with the following content:</p><pre>//<br>//  YourName.metal<br>//  YourProject<br>//<br><br>#include &lt;metal_stdlib&gt;<br>using namespace metal;</pre><p>The <em>Metal </em>file must contain code written in <em>Metal Shading Language, </em>which is very similar to C++.</p><h3>So, what cool things can you do with a Metal file?</h3><p>In SwiftUI, you can turn these into custom view modifiers — here are three neat examples:</p><p><strong>Color Effect:</strong></p><pre>[[stitchable]] half4 name(float2 position, half4 color, /* your extra args… */)</pre><ul><li><strong>position</strong> (<em>float2</em>): where we are on the screen</li><li><strong>color</strong> (<em>half4</em>): the pixel’s current color</li><li><strong>returns</strong> a new <em>half4</em> color after you tweak it!</li></ul><p><strong>Distortion Effect:</strong></p><pre>[[stitchable]] float2 name(float2 position, /* your extra args… */)</pre><ul><li><strong>position</strong> (<em>float2</em>): the pixel’s spot in your view</li><li><strong>returns</strong> a new <em>float2</em>position so you can warp things around</li></ul><p><strong>Layer Effect:</strong></p><pre>[[stitchable]] half4 name(float2 position, SwiftUI::Layer layer, /* your extra args… */)</pre><ul><li><strong>position</strong> (<em>float2</em>): pixel location</li><li><strong>layer</strong> (<em>SwiftUI::Layer</em>): lets you sample whatever’s underneath</li><li><strong>returns</strong> a <em>half4 </em>color that mixes in that layer’s content</li></ul><h3>How can we whip up a parallax distortion effect?</h3><p>To craft a sweet parallax effect, we’ll write a [[stitchable]] distortion shader that nudges each pixel’s sample point based on the size of the view and an offset value. For example:</p><pre>[[ stitchable ]] float2 parallaxEffect(float2 position, float2 size, float offset) {<br>  float diagonalY = -((size.y / size.x) * position.x) + size.y;<br>  <br>  if (position.y &gt; diagonalY) {<br>    return float2(position.x + size.x*offset, position.y - size.y*offset);<br>  } else {<br>    return float2(position.x - size.x*offset, position.y + size.y*offset);<br>  }<br>}</pre><p>Initially, we can define the float <em>diagonalY</em> as the diagonal from the bottom left to the top right to shift diagonally the upper part to the left, while the lower part to the right.</p><p>Then, we can check if the <em>position.y </em>is greater than <em>diagonalY, </em>so we can shift the position to the right; otherwise, we shift it to the left.</p><p>Alright, let’s plug our <em>parallaxEffect </em>right into SwiftUI! First, we’ll wrap it up in a handy ViewModifier:</p><pre>struct ParallaxTransitionModifier: ViewModifier {<br>  var offset: Float<br>  <br>  func body(content: Content) -&gt; some View {<br>    content<br>      .visualEffect({ content, proxy in<br>        content<br>          .distortionEffect(<br>            ShaderLibrary.parallaxEffect(<br>              .float2(proxy.size),<br>              .float(offset)<br>            ),<br>            maxSampleOffset: .zero)<br>      })<br>  }<br>}</pre><p>Here’s the scoop:</p><ul><li>We grab the view’s size using <em>.visualEffect {…}</em>, which hands us a <strong>proxy.size</strong>.</li><li>We feed that size and our custom<em> offset </em>into <strong>ShaderLibrary.parallaxEffect</strong>.</li><li>No need to worry about individual pixel positions — Metal handles all of that heavy lifting under the hood!</li></ul><p>And now let’s stitch it all together with a sweet custom transition for our images:</p><pre>extension AnyTransition {<br>  static func parallaxTransitionEffect() -&gt; AnyTransition {<br>    // How it appears<br>    let insertion = AnyTransition.modifier(<br>      active: ParallaxTransitionModifier(offset: 1),<br>      identity: ParallaxTransitionModifier(offset: 0))<br>    <br>    // How it disappears<br>    let removal = AnyTransition.modifier(<br>      active: ParallaxTransitionModifier(offset: -1),<br>      identity: ParallaxTransitionModifier(offset: 0))<br>    <br>    // Asymmetric gives us a different in-and-out vibe  <br>    return .asymmetric(insertion: insertion, removal: removal)<br>  }<br>}</pre><p>Then in our <strong>ContentView</strong>, we simply use it like this:</p><pre>struct ContentView: View {<br>  <br>  @State private var index: Int = 0<br>  <br>  private let images: [UIImage] = [.guldo, .recoome, .burter, .jeeth, .ginyu]<br>  <br>  var body: some View {<br>    Image(uiImage: images[index])<br>      .resizable()<br>      .scaledToFit()<br>      .id(index)<br>      .transition(.parallaxTransitionEffect())<br>      .onTapGesture {<br>        withAnimation(.easeInOut(duration: 1)) {<br>          if index == images.count - 1 {<br>            index = 0<br>          } else {<br>            index += 1<br>          }<br>        }<br>      }<br>  }<br>}</pre><p>Tap to see the parallax magic in action, and watch your images glide in and out with that depthy feel!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*thgY4FZTTd0Ts1A2Kpg58g.gif" /><figcaption>Parallax Effect</figcaption></figure><h3>Next Steps</h3><ol><li>Copy the snippets</li><li>Create your Custom Effect</li><li>Show it to your colleagues</li></ol><blockquote><strong><em>Try it out</em></strong><em> and let me know: which effect will you apply to your views? Drop a comment below and save this post to always have it at hand! 🚀</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b8c6744480b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tricks | Tips: SwiftData + ProtoBuf for Custom DataStore]]></title>
            <link>https://medium.com/@emilioarvonio/swiftdata-protobuf-for-custom-datastore-bfc65e9c1cf3?source=rss-76e1571868f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfc65e9c1cf3</guid>
            <category><![CDATA[protobuf]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[custom]]></category>
            <category><![CDATA[swiftdata]]></category>
            <dc:creator><![CDATA[Emilio Arvonio]]></dc:creator>
            <pubDate>Tue, 08 Jul 2025 17:39:24 GMT</pubDate>
            <atom:updated>2025-07-08T17:39:24.380Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5XImE1CE97-IiI-Qrff-_g.png" /></figure><p>Hey Devs!</p><p>Have you ever considered saving data efficiently on your phone? With SwiftData, it’s possible! Let’s see <em>how</em> we can do that in 5 minutes using <strong>Protocol Buffers</strong> created by Google.</p><h3>Which Item Must Be Saved?</h3><p>Our goal is to save several <em>ToDoItems</em> into our App to track what we need to do during our day. That Item is defined just like this:</p><pre>import Foundation<br>import SwiftData<br><br>@Model<br>final class ToDoItem: Codable, Identifiable {<br>    var title: String<br>    var isDone: Bool<br>    var creationDate: Date<br><br>    init(title: String, isDone: Bool = false) {<br>        self.title = title<br>        self.isDone = isDone<br>        self.creationDate = .now<br>    }<br><br>    enum CodingKeys: String, CodingKey {<br>        case title, isDone, creationDate<br>    }<br><br>    required init(from decoder: any Decoder) throws {<br>        let container = try decoder.container(keyedBy: CodingKeys.self)<br>        self.title = try container.decode(String.self, forKey: .title)<br>        self.isDone = try container.decode(Bool.self, forKey: .isDone)<br>        self.creationDate = try container.decode(Date.self, forKey: .creationDate)<br>    }<br><br>    func encode(to encoder: any Encoder) throws {<br>        var encoder = encoder.container(keyedBy: CodingKeys.self)<br>        try container.encode(title, forKey: .title)<br>        try container.encode(isDone, forKey: .isDone)<br>        try container.encode(creationDate, forKey: .creationDate)<br>    }<br>}</pre><h3>Why Protobuf?</h3><p>Protobuf is a Google invention for serialising data efficiently. It defines structured data using <strong>.proto schema files</strong>, where message types are declared with fields that have unique tags for identification.</p><p>Each field has a type, such as integers, strings, or nested messages, and can be marked as <strong>optional</strong> or <strong>repeated</strong>. When compiled, these definitions generate code in various languages, allowing for efficient data serialization and deserialization.</p><p>The language is designed to be <strong>compact, fast, and backwards-compatible</strong>, making it ideal for communication between services or for long-term data storage.</p><p>First things first, let’s create the <strong>DataStore.proto</strong> file as follows:</p><pre>// DataStore.proto<br>syntax = &quot;proto3&quot;;<br><br>// A message representing the snapshot information<br>message ModelDataIdentifierImplementation {<br>    string entity_name = 1;<br>    bool is_temporary = 2;<br>    string primary_key = 3;<br>    string store_identifier = 4;<br>    string uri_representation = 5;<br>}<br><br>// A message to contain ModelDataIdentifierImplementation<br>message ModelDataIdentifier {<br>    ModelDataIdentifierImplementation implementation = 1;<br>}<br><br>// A message representing a single persistent model.<br>message ModelData {<br>    string creation_date = 1;      <br>    bool is_done = 2;     <br>    string title = 3;        <br>    ModelDataIdentifier persistentIdentifier = 4;<br>}<br><br>// The root message containing all of our data.<br>message Store {<br>    repeated ModelData models = 1;<br>}</pre><blockquote>We’re creating a store that contains to-do items created in the App.</blockquote><p>Now, run the <strong>protoc</strong> compiler to generate the <strong>DataStore.pb.swift </strong>file we&#39;ll use in our code.</p><p>Open your terminal, navigate to the folder where you saved <strong>DataStore.proto</strong>, and run this command:</p><pre>protoc --swift_out=. DataStore.proto</pre><p>Add the generated <strong>DataStore.pb.swift</strong> file to your target in Xcode.</p><h3>What about a SwiftData?</h3><p>To define a custom <strong>DataStore</strong>, we need to use the three different protocols that SwiftData offers.</p><p><strong>DataStoreConfiguration:</strong></p><pre>import Foundation<br>import SwiftData<br><br>// Configuration for our Protobuf-backed store<br>final class ProtobufStoreConfiguration: DataStoreConfiguration {<br>    typealias Store = ProtobufStore<br><br>    var name: String<br>    var schema: Schema?<br>    var fileURL: URL<br><br>    init(name: String, schema: Schema? = nil, fileURL: URL) {<br>        self.name = name<br>        self.schema = schema<br>        self.fileURL = fileURL<br>    }<br><br>    static func == (lhs: ProtobufStoreConfiguration, rhs: ProtobufStoreConfiguration) -&gt; Bool {<br>        return lhs.name == rhs.name<br>    }<br><br>    func hash(into hasher: inout Hasher) {<br>        hasher.combine(name)<br>    }<br>}</pre><p>This protocol defines which Store is going to be used by the specified configuration</p><p><strong>DataStoreSnapshot:</strong></p><pre>import Foundation<br>import SwiftData<br><br>struct ToDoItemSnapshot: DataStoreSnapshot{<br>    var persistentIdentifier: PersistentIdentifier<br>    let title: String<br>    let isDone: Bool<br>    let creationDate: Date<br><br>    init(persistentIdentifier: PersistentIdentifier, title: String, isDone: Bool, creationDate: Date) {<br>        self.persistentIdentifier = persistentIdentifier<br>        self.title = title<br>        self.isDone = isDone<br>        self.creationDate = creationDate<br>    }<br><br>    init(from: any BackingData, relatedBackingDatas: inout [PersistentIdentifier : any BackingData]) {<br>        self.persistentIdentifier = from.persistentModelID!<br>        self.title = (from as? (any BackingData&lt;ToDoItem&gt;))?.getValue(forKey: \ToDoItem.title) ?? &quot;&quot;<br>        self.isDone = (from as? (any BackingData&lt;ToDoItem&gt;))?.getValue(forKey: \ToDoItem.isDone) ?? false<br>        self.creationDate = (from as? (any BackingData&lt;ToDoItem&gt;))?.getValue(forKey: \ToDoItem.creationDate) ?? .now<br>    }<br><br>    func copy(persistentIdentifier: PersistentIdentifier, remappedIdentifiers: [PersistentIdentifier : PersistentIdentifier]? = nil) -&gt; ToDoItemSnapshot {<br>        return ToDoItemSnapshot(<br>            persistentIdentifier: persistentIdentifier,<br>            title: self.title,<br>            isDone: self.isDone,<br>            creationDate: self.creationDate)<br>    }<br>}</pre><p>This is a custom snapshot used by SwiftData to track new changes made to the <em>ToDoItems. W</em>e created it to make it easier to save items locally via the <strong>protobuf</strong> protocol.</p><p><strong>DataStore:</strong></p><pre>import Foundation<br>import SwiftData<br>import SwiftProtobuf<br><br>final class ProtobufStore: DataStore {<br>    typealias Configuration = ProtobufStoreConfiguration<br>    typealias Snapshot = ToDoSnapshot<br><br>    var configuration: ProtobufStoreConfiguration<br>    var name: String<br>    var schema: Schema<br>    var identifier: String<br><br>    init(_ configuration: ProtobufStoreConfiguration, migrationPla: (any SchemaMigrationPlan.Type)?) throws {<br>        self.configuration = configuration<br>        self.name = configuration.name<br>        self.schema = configuration.schema ?? Schema()<br>        self.identifier = configuration.fileURL.lastPathComponent<br>    }<br><br>    func fetch&lt;T&gt;(_ request: DataStoreFetchRequest&lt;T&gt;) throws -&gt; DataStoreFetchResult&lt;T, ToDoItemSnapshot&gt; where T : PersistenModel {<br>        if request.descriptor.predicate != nil {<br>            throw DataStoreError.preferInMemoryFilter<br>        } else if request.descriptor.sortBy.count &gt; 0 {<br>            throw DataStoreError.preferInMemorySort<br>        }<br><br>        let model = try self.read()<br>        let snapshot = models.values.map { $0 }<br>  <br>        return DataStoreFetchResult(descriptor: request.descriptor, fetchedSnapshots: snapshots, relatedSnapshots: models)<br>    }<br><br>    func save(_ request: DataStoreSaveChangesRequest&lt;ToDoItemSnapshot&gt;) throws -&gt; DataStoreSaveChangesResult&lt;ToDoItemSnapshot&gt; {<br>        var newPersistentIdentifiers = [PersistentIdentifier : PersistentIdentifier]()<br>        var serializedModels = try self.read()<br><br>        for snapshot in request.inserted {<br>            let newIdentifier = try PersistentIdentifier.identifier(for: identifier, entityName: snapshot.persistentIdentifier.entityName, primaryKey: UUID())<br>            <br>            let newSnapshot = snapshot.copy(persistentIdentifier: newIdentifier)<br>            serializedModels[newIdentifier] = newSnapshot<br>            newPersistentIdentifiers[snapshot.persistentIdentifier] = newIdentifier<br>        }<br><br>        for snapshot in request.updated {<br>            serializedModels[snapshot.persistentIdentifier] = snapshot<br>        }<br><br>        for snapshot in request.deleted {<br>            serializedModels[snapshot.persistentIdentifier] = nil<br>        }<br><br>        try self.write(serializedModels)<br>        return DataStoreSaveChangesResult(for: self.identifier, remappedIdentifiers: newPersistentIdentifiers)<br>    }<br><br>    private func read() throws -&gt; [PersistentIdentifier : ToDoItemSnapshot] {<br>        do {<br>          let data = try Data(contentsOf: configuration.fileURL)<br>          let store = try Store(serializedBytes: data)<br><br>          let formatter = DateFormatter()<br>          formatter.dateFormat = &quot;yyyy-MM-dd&#39;T&#39;HH:mm:ss&#39;Z&#39;&quot;<br><br>          let models = store.models.compactMap { modelData -&gt; ToDoItemSnapshot? in<br>            let persistentIdentifier: PersistentIdentifier? = try? .identifier(<br>                for: identifier,<br>                entityName: modelData.persistentIdentifier.implementation.entityName,<br>                primaryKey: modelData.persistentIdenfitier.implementation.primaryKey)<br><br>            if let persistentIdentifier {<br>                let snapshot = ToDoItemSnapshot(<br>                    persistentIdentifier: persistentIdentifier,<br>                    title: modelData.title,<br>                    isDone: modelData.isDone,<br>                    creationDate: formatter.date(from: modelData.creationDate) ?? .now)<br><br>                return snapshot<br>            } else { return nil }<br>          }<br><br>          var results = [PersistentIdentifier : ToDoItemSnapshot]()<br><br>          models.forEach { model in<br>              results[model.persistentIdentifier] = model<br>          }<br><br>          return results<br>        } catch {<br>            return [:]<br>        }<br>    }<br><br>    private func write(_ models: [PersistentIdentifier : ToDoItemSnapshot]) throws {<br>        var store = Store()<br><br>        store.models = models.values.map {<br>            var modelDataIdentifierImplementation = ModelDataIdentifierImplementation()<br>            modelDataIdentifierImplementation.entityName = $0.peristentIdentifier.entityName<br>            modelDataIdentifierImplementation.isTemporary = false<br>            modelDataIdentifierImplementation.primaryKey = UUID().uuidString<br>            modelDataIdentifierImplementation.storeIdentifier = identifier<br><br>            var modelDataIdentifier = ModelDataIdentifier()<br>            modelDataIdentifier.implementation = modelDataIdentifierImplementation<br><br>            var modelData = ModelData()<br>            modelData.title = $0.title<br>            modelData.isDone = $0.isDone<br>            modelData.creationDate = $0.creationDate.ISO8601Format()<br>            modelData.persistenIdentifier = modelDataIdentifier<br><br>            return modelData<br>        }<br><br>        let data = try store.serializedData()<br>        try data.write(to: configuration.fileURL, options: .atomic)<br>    }<br>}</pre><p>A lightweight SwiftData <strong>DataStore</strong> Implementation using <strong>Protocol Buffers </strong>for on-disk persistence. <strong>ProtobufStore </strong>maps between in-memory <strong>ToDoItemSnapshot</strong> structs and a binary <strong>.pb</strong> file via SwiftProtobuf, handling all CRUD operations and identifier management.</p><ul><li><strong>init(_ configuration: ProtobufStoreConfiguration, migrationPlan: …?)</strong><br> Initialises the store with its configuration (file URL, name, schema) and sets up its unique identifier.</li><li><strong>fetch&lt;T&gt;(_ request: DataStoreFetchRequest&lt;T&gt;)<br></strong>Reads the entire <strong>Protocol Buffers</strong> file via <strong>read()</strong> method and converts stored messages into <strong>ToDoItemSnapshot</strong> instances to return a <strong>DataStoreFetchResult</strong> containing all snapshots and any related lookup map</li><li><strong>save(_ request: DataStoreSaveChangesRequest&lt;ToDoItemSnapshot&gt;)</strong><br>Loads the current snapshot map with <strong>read() </strong>method. Then generates new <strong>PersistentIdenfiers</strong> and records the remappings.<br>Writes the updated map back to disk atomically via <strong>write(_:)</strong> method and returns a DataStoreSaveChangesResult with all identifier remappings</li><li><strong>private func read() -&gt; [PersistentIdentifier: ToDoItemSnapshot]</strong><br>Attempts to load raw bytes from the configured file URL. Deserialises them into our generated <strong>Store</strong> to recreate each ToDoItemSnapshot</li><li><strong>private func write(_ models: [PersistentIdentifier: ToDoItemSnapshot])</strong><br>Creates a new <strong>Store</strong> proto message and maps each <strong>ToDoItemSnapshot</strong> back into a <strong>ModelData</strong>. Finally, we can serialise the <strong>Store</strong> to bytes and write it atomically to the file URL</li></ul><h3>How can we use it?</h3><p>Let’s define our custom <strong>ModelContainer </strong>in our <em>ToDoApp</em> as follows:</p><pre>import SwiftUI<br>import SwiftData<br><br>@main<br>struct ToDoApp: App {<br>    var modelContainer: ModelContainer = {<br>        do {<br>            let fileURL = try FileManager<br>                .default<br>                .url(/service/for: .documentDirectory,<br>                     in: .userDomainMask,<br>                     appropriateFor: nil,<br>                     create: true)<br>                .appendingPathExtension(&quot;datastore.bin&quot;)<br><br>            let configuration = ProtobufStoreConfiguration(name: &quot;ProtobufStore&quot;, fileURL: filerURL)<br><br>            return try ModelContainer(for: ToDoItem.self, configurations: configuration)<br>        } catch {<br>            fatalError(&quot;Failed to inizialise ModelContainer: \(error)&quot;)<br>        }<br>    }()<br><br>    var body: some Scene {<br>        WindowGroup {<br>            ContentView()<br>        }<br>        .modelContainer(modelContainer)<br>    }<br>}</pre><h3>Next Steps</h3><ol><li>Copy the snippets</li><li>Create your Custom DataStore</li><li>Save your data locally</li></ol><blockquote><strong><em>Try it out</em></strong><em> and let me know: how did your performance or reliability improve? Drop a comment below and save this post to always have it at hand! 🚀</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfc65e9c1cf3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tricks | Tips: Build Your Own Actor Executor in Swift]]></title>
            <link>https://medium.com/@emilioarvonio/build-your-own-actor-executor-in-swift-dbaa4bf7718f?source=rss-76e1571868f3------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbaa4bf7718f</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[actors]]></category>
            <category><![CDATA[tricks]]></category>
            <category><![CDATA[concurrency]]></category>
            <dc:creator><![CDATA[Emilio Arvonio]]></dc:creator>
            <pubDate>Mon, 30 Jun 2025 06:55:46 GMT</pubDate>
            <atom:updated>2025-06-30T06:55:46.855Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*-SHePQhjCC8fqwp-31R8QQ.png" /></figure><p>Hey Devs!<br>Ever wondered how to get full control over <em>where</em> your Swift actors run? Let’s roll up our sleeves and build a custom executor in under 5 minutes.</p><h3>Why a Custom Executor?</h3><p>By default, Swift actors run on a shared thread pool. Fine for most cases, but:</p><ul><li><strong>Blocking work</strong> (disk, database, network) can starve other tasks.</li><li><strong>QoS control</strong> is impossible — everything shares the same priority.</li></ul><p>A custom executor carves out a private “stage” for your actor, so it never fights for thread time. Give your actor its own with a <strong>SerialExecutor</strong>:</p><pre>import Dispatch<br><br>// 1) Define a SerialExecutor on a private DispatchQueue<br>final class SerialQueueExecutor: SerialExecutor {<br>  private let queue = DispatchSerialQueue(label: &quot;com.yourapp.actor&quot;)<br><br>  func enqueue(_ job: consuming ExecutorJob) {<br>    let unowned = UnownedJob(job)<br>    queue.async { <br>      unowned.runSynchronously(on: self.asUnownedSerialExecutor()) <br>    }<br>  }<br><br>  func asUnownedSerialExecutor() -&gt; UnownedSerialExecutor {<br>    UnownedSerialExecutor(ordinary: self)<br>  }<br>}<br><br>// 2) Attach it to your actor<br>actor FileManagerActor {<br>  nonisolated let executor = SerialQueueExecutor()<br>  nonisolated var unownedExecutor: UnownedSerialExecutor {<br>    executor.asUnownedSerialExecutor()<br>  }<br><br>  func save() async {<br>    // heavy or blocking logic here<br>  }<br>}</pre><blockquote>Every await FileManagerActor().save() now runs on <strong>your</strong> “com.yourapp.actor” queue—isolated, dedicated, and QoS-hed.</blockquote><h3>What about my tasks?</h3><p>You can also have a dedicated queue for your Tasks (not just your actors). Implement <strong>TaskExecutor</strong>:</p><pre>final class TaskQueueExecutor: TaskExecutor {<br>  private let queue = DispatchQueue(label: &quot;com.yourapp.task&quot;, qos: .userInitiated)<br><br>  func enqueue(_ job: consuming ExecutorJob) {<br>    let unowned = UnownedJob(job)<br>    queue.async {<br>      unowned.runSynchronously(on: self.asUnownedTaskExecutor())<br>    }<br>  }<br><br>  func asUnownedTaskExecutor() -&gt; UnownedTaskExecutor {<br>    UnownedTaskExecutor(ordinary: self)<br>  }<br>}<br><br>// Usage:<br>let taskExecutor = TaskQueueExecutor()<br><br>Task(executorPreference: taskExecutor) {<br>  // This runs on com.yourapp.task<br>  await someAsyncFunction()<br>}</pre><blockquote>Your Task now always fires on <strong>your</strong> “com.yourapp.task” queue—no more default pool hopping.</blockquote><h3>Can we unify them?</h3><p>Of course! Combine both protocols so that the same queue serves <em>actors</em> and <em>tasks</em>:</p><pre>final class CombinedSerialExecutor: SerialExecutor, TaskExecutor {<br>  private let queue = DispatchSerialQueue(label: &quot;com.yourapp.executor&quot;, qos: .userInitiated)<br><br>  // SerialExecutor<br>  func enqueue(_ job: consuming ExecutorJob) {<br>    let unowned = UnownedJob(job)<br>    queue.async { unowned.runSynchronously(on: self.asUnownedSerialExecutor()) }<br>  }<br>  func asUnownedSerialExecutor() -&gt; UnownedSerialExecutor {<br>    UnownedSerialExecutor(ordinary: self)<br>  }<br><br>  // TaskExecutor<br>  func asUnownedTaskExecutor() -&gt; UnownedTaskExecutor {<br>    UnownedTaskExecutor(ordinary: self)<br>  }<br>}<br><br>actor FileManagerActor {<br>  nonisolated let executor = CombinedSerialExecutor()<br>  nonisolated var unownedExecutor: UnownedSerialExecutor {<br>    executor.asUnownedSerialExecutor()<br>  }<br><br>  func save() async { /* … */ }<br>}<br><br>let combinedSerialExec = CombinedSerialExecutor()<br><br>// Spawn a task on the same queue:<br>Task(executorPreference: combinedSerialExec) {<br>  await FileManagerActor().save()<br>}</pre><blockquote><strong>Actors</strong> and standalone <strong>tasks</strong> now share your “com.yourapp.executor” queue—perfect for tight coupling or ordered workloads.</blockquote><h3>Next Steps</h3><ol><li>Copy the snippets</li><li>Swap in your queue label or QoS settings</li><li>Call your actor methods with <strong>await </strong>as usual</li></ol><p>Your actor (and/or tasks) now run on a private, dedicated thread context — ideal for blocking I/O, priority control, or deterministic ordering.</p><blockquote><strong><em>Try it out</em></strong><em> and let me know: how did your performance or reliability improve? Drop a comment below and save this post to always have it at hand! 🚀</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbaa4bf7718f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>