跪拜 Guibai
← Back to the summary

Swift Weekly #164: Keep Your Code Personal When AI Writes It

My Code, My Call -- Dongpo Zhouzi's Swift Weekly #164

issue164.webp

My Code, My Call

Today, many developers who write code with the help of AI agents rarely review every implementation line by line; their "control" over a project relies more on a few rule documents. As projects grow, their sense of detachment from their own code also grows. When you want to intervene in certain steps, you often find you don't know where to start.

As a developer who wants to retain a personal style even if I don't hand-write every line, I've been looking for a way to leave my own trace in projects. It's not just about a sense of presence; I believe that in many scenarios, I still possess abilities that AI cannot yet replace.

Fortunately, while developing my own small App recently, I found a way to let personal style and technical ideas blend more naturally into the project. Judging by the results so far, I'm quite satisfied.

As a blogger, I've written hundreds of technical articles over the past few years; as a weekly editor, I've recommended hundreds of excellent pieces based on my technical judgment and preferences. During project development, when AI's implementation doesn't meet my expectations, I often hand over my own articles, third-party libraries I've built, or articles I've read deeply and recommended, and let AI use the ideas in them as references. Compared to dry rule constraints, complete articles or source code often contain specific context, design motivation, technical trade-offs, and implementation examples, making it easier for AI to accurately grasp my intent.

The result is that even though the code in my project now is a product of multiple different models, I can still clearly recognize my style and traces within it. This doesn't mean my ideas are always better than AI's chosen implementations, but the familiarity gives me back a real sense of the project's code. Although the code isn't written by me, many of the technical decisions are still mine.

To keep this "sense of control" alive, continuing to produce content that reflects personal style, technical judgment, and design thinking might become one of my future directions.

For many developers, since AI has significantly improved the efficiency of code implementation, can we use the saved time to broaden technical horizons, explore different implementation approaches, and organize and record our own experiences and ideas? This accumulation not only enhances our technical judgment but also, in turn, guides AI to produce better implementations.

In future technical writing, "humans" may no longer be the only audience. Besides helping readers understand the author's ideas, how to make AI accurately understand and put those ideas into practice will become an important consideration in writing.

This Issue | Previous Issue | All Weekly Issues

Recent Recommendations

ActorRPC: A Swift Distributed Actor Experiment Based on HTTP

Swift's Distributed Actors have been around for years, but since the typical application scenarios are mostly stateful distributed clusters inside data centers, this language feature still feels distant to most Swift developers. Recently, Simon Leeb used the new Embedded Swift support for Distributed added to Swift's main branch to build an end-to-end pure Swift RPC proof-of-concept project called ActorRPC, demonstrating another possibility: bringing Swift a type-safe, full-stack development experience similar to tRPC in the TypeScript ecosystem.

In the author's online treasure-hunt game, the frontend is compiled with Embedded Swift to Wasm and runs in the browser, calling a distributed actor deployed on AWS Lambda via ordinary JSON POST requests. The frontend and backend share a @Resolvable protocol as the shared API contract, with no extra schema definition or code generation. The whole scheme doesn't involve cluster management mechanisms, can fully utilize existing HTTP infrastructure, and can integrate with server-side frameworks like Vapor and Hummingbird.

I think the most interesting part of this project is that the value of Distributed Actors isn't just about making actors run across processes; it's also that the Swift compiler already provides a language-level, type-safe remote call mechanism. Even if developers don't need traditional distributed actor systems, they can still use this part independently.


Overuse of weak: Debugging a Swift Miscompilation Crash

Many developers, when refactoring Swift code, habitually keep [weak self] even when the closure is no longer escaping, thinking that an extra weak reference is harmless. Matthias Gansrigler-Hrad documents a frustrating crash: completely valid code, due to an extra [weak self], triggers a compiler bug under Swift 6.4.2 (Xcode 27.2) Release optimization, causing the app to crash at guard let self, while Debug mode cannot reproduce it at all.

With AI's help analyzing assembly and SIL, Matthias finally traced the issue to a compiler optimization: to reduce heap allocation, the compiler tries to move captured variables to the stack in Release builds. However, when the closure also captures and modifies an external local variable and uses [weak self], this optimization seems to misjudge the lifetime of the weak reference, releasing its storage before the closure executes, leading to a crash. Since the default Debug build doesn't enable this optimization, the same code runs fine during development. Removing [weak self] or the modification to the local variable avoids the problem.

This article brings two practical engineering reminders: first, don't habitually use [weak self] in non-escaping closures; unnecessary code can introduce unexpected complexity. Second, don't rely solely on Xcode's default Debug build for testing; compiler optimizations can make the same code behave drastically differently, so be sure to thoroughly test Release builds before distributing.


Building a Zero-Wakeup macOS Screenshot App and Cutting Core ML OCR Memory by 4x

For tools that live in the menu bar and are triggered on demand, idle resource usage is just as important as performance during tasks. Morax Cheng shares a series of performance optimization practices for the open-source native macOS screenshot and screen recording tool OhMyShot: lazily querying camera and microphone authorization to avoid implicit AVFoundation initialization, using AppKit for the resident UI, delegating update checks to system background task scheduling, and using mmap to solve the problem of large memory blocks being released but still cached by libmalloc. Currently, the app reaches 0 wakeups and 26 MB memory usage in idle state after launch.

On the OCR side, the author discovered that Core ML accumulates buffers needed for data transfer between the Neural Engine and CPU when handling inputs of varying widths. By moving the last layer of the recognition model out of Core ML and using the Accelerate framework to perform the relevant computation on the CPU, Morax managed to reduce peak memory from about 1.5 GB to under 363 MB in two test sets, while also improving recognition speed and maintaining roughly the same accuracy. The article also describes how to use multi-round recognition, pixel scanning, and geometric analysis to compensate for Apple Vision's shortcomings in recognizing code indentation, standalone brackets, and editor line numbers.

Surprisingly, this article comes from a Chinese high school developer. In an era where many desktop apps use hundreds of MB of background memory, he not only insists on native development but also sets explicit performance budgets from the start, continuously validating and optimizing through quantitative testing, and open-sourcing the entire project under GPL-3.0. A look at his personal homepage reveals that, beyond his own projects, he has contributed nearly 100 merged PRs to open-source projects like Rust Clippy, Apache DataFusion, and Homebrew. To see such young developers exhibit this rigorous engineering attitude, pursuit of software quality, and sustained investment in the open-source community is truly inspiring.


Adding Distinctive Patterns for Categorical Data in Swift Charts

In data visualization, relying solely on color to differentiate categories is often unfriendly to users with color vision deficiencies. Matthaus Woolard demonstrates how to use SwiftUI's Image(size:renderer:) and ImagePaint to dynamically generate repeating fill patterns like diagonal lines, dots, and checkerboards without extra image assets, and uses chartForegroundStyleScale so Swift Charts bar charts and legends automatically adopt consistent fill styles. More cleverly, through a custom ShapeStyle, the author responds to the accessibilityDifferentiateWithoutColor environment value in resolve(in:), so when the user enables the "differentiate without color" accessibility option, the chart automatically overlays textures on top of the original colors, with no changes to the chart's declaration code. This design pattern of wrapping environment response logic inside a style is worth borrowing in other SwiftUI contexts.


Building Apps Is a System Design Exercise

How do you make a voice message sent by a friend break through iPhone's silent mode and play directly as a full-screen alarm? Jacob Bartlett uses his retro iPod-style app UltraPing as an example, showing a clever combination of APIs: using a push notification to trigger a Notification Service Extension, downloading the other party's recorded audio in the background and storing it in an App Group shared directory, then calling AlarmKit to schedule an immediately triggered alarm with that recording as the custom ringtone.

Around this core mechanism, Jacob starts by validating the most uncertain technical links, then gradually introduces object storage, databases, stateless cloud functions, push services, and a mutual-consent user pairing mechanism, ultimately building a complete end-to-end system. Throughout the process, each stage has a working prototype, and the developer's focus shifts from implementation details to the responsibilities and coordination of the system's components.

If Jacob hadn't written this down, this combination would likely have remained his secret for a long time. While thanking him for his selfless sharing, I also admire his creativity in seamlessly interlocking the client, cloud, storage, and underlying system mechanisms into a reliable whole.

Tools

swift-rrule: Parse and Calculate iCalendar Recurrence Rules with Swift

swift-rrule is a Swift library open-sourced by Mattt for parsing RFC 5545 standard iCalendar recurrence rules (RRULE), calculating recurrence event dates, and generating localized natural language descriptions (currently supporting English, German, Spanish, and French), along with bidirectional conversion to Foundation's native Calendar.RecurrenceRule. The library has an independent date calculation engine and supports iOS 16 / macOS 13 and above.

In the companion article, Mattt starts with the limitations of traditional cron expressions in describing "the first Sunday of every month" and the historical evolution of the US Thanksgiving date rule, introducing the expressive power of iCalendar recurrence rules. He also points out that Apple's Calendar.RecurrenceRule, introduced in iOS 18 / macOS 15, lacks string parsing and natural language formatting capabilities, and also deviates from RFC standards when calculating rules like "all Tuesdays of the month" or "the last working day of the month". This is the reason he wrote swift-rrule.


Flocon: Let AI Assistants See Your App's Runtime State

Inspired by Meta Flipper, Flocon, maintained by Florent Champigny, is an open-source cross-platform app debugging tool. It aggregates network requests, logs, events, and crash information from the app into a unified timeline on the desktop, and exposes these debugging capabilities to AI assistants like Codex, Claude Code, and Cursor through a built-in local MCP Server. Besides analyzing app behavior, AI assistants can proactively simulate network responses, create weak network conditions, trigger deep links, and even capture the UI to efficiently locate and verify problems.

For Swift developers, the standalone FloconSwift SDK can be integrated via Swift Package Manager, enabling on-demand network monitoring (URLSession / gRPC / GraphQL), file browsing, UserDefaults and Keychain inspection, and even running SQL queries on underlying SQLite databases like Core Data or GRDB. Additionally, the SDK leverages SwiftPM's Package Trait mechanism, letting developers cleanly strip debugging features from release builds without changing business code.


Kido: Run macOS Command-Line Tools on ARM64 Linux

Developed by Cocoa, the open-source project Kido brings Docker-like container workflows to Darwin. Developers can use kido run to start an environment, use Kidofile to package tools and dependencies into images, and distribute them through standard OCI image registries. Unlike conventional containers, each Kido instance is a microVM with an independent XNU kernel. On Apple silicon it leverages Virtualization.framework, and on ARM64 Linux it uses the built-in KVM VMM. Base images are only about 30 MB, startup takes around one second, and system runtimes like Swift Runtime and system libraries can be installed on demand via the package manager kl.

Even more interesting, Kido offers an online playground that uses WebAssembly and WebGPU to run the Darwin kernel directly in the browser, with support for Metal 3 Compute operations. Although the project is still experimental and doesn't support full macOS applications or Apple's native toolchain, this lightweight, standardized approach to Darwin environments opens up new possibilities for cloud builds, automated testing, and isolated execution environments for coding agents.

In my previous editorial macOS for the Masses, or macOS for Developers?, I discussed using virtualization to ease the conflict between macOS security mechanisms and the autonomous execution needs of agents. Kido wasn't created to solve that problem, but the direction it explores is enlightening: developers may not always need a full macOS; sometimes they just want a lightweight, isolated, on-demand Darwin execution environment. If such approaches mature, they could reduce the privilege management cost for local agents and open more choices for cloud development and automated validation in the Apple ecosystem.


SAGA: When AI Makes Cross-Language Porting a New Technical Choice

SAGA (Swift Alternative GPU API) is a fully Swift-implemented cross-platform GPU SDK, consisting of an independent shader compiler and a GPU runtime with WebGPU-style APIs. The project was initiated by Vladislav Prusakov, the author of Ada Engine. According to the author's description, with the help of AI agents, he completed the initial port of the core capabilities of the Naga compiler and wgpu graphics framework from the Rust ecosystem in just three days, avoiding the complexity of introducing a Rust toolchain and cross-language bridging into Swift graphics projects. Currently, SAGA can run on multiple platforms through backends like Metal, Vulkan, Direct3D 12, and WebGPU, and offers conversions between several shader languages, though it still has a long way to go to achieve full feature parity with the original projects.

Compared to how much functionality SAGA currently provides, the attempt itself is perhaps more noteworthy. In the past, when faced with mature cross-language infrastructure, developers could only accept existing dependencies or invest significant resources in reimplementation. Now, AI has drastically lowered the cost of code porting and initial implementation, allowing independent developers to rebuild underlying tools according to their own technical preferences. While long-term maintenance, compatibility, and correctness verification remain unavoidable challenges, SAGA demonstrates a new possibility: when implementation cost is no longer an insurmountable barrier, developers may gain greater freedom of technical choice.

Previous Issues

💝 Support and Feedback

If this weekly has helped you, please:


🚀 Expand Your Swift Horizons

  • 📮 Email Subscription | weekly.fatbobman.com for exclusive technical insights
  • 👥 Developer Community | Discord for real-time experience exchange
  • 📚 Original Tutorials | fatbobman.com for Swift/SwiftUI best practices
Comments

Top 1 from juejin.cn, machine-translated. The original thread is authoritative.

season_zhu 1 likes

Distill yourself, illuminate AI.