Roman Li

@romanli
3 Followers
8 Following
31 Posts
ios developer and mentor
linkedinhttps://www.linkedin.com/in/rmnl/

About Advanced observation tracking (SE-0506).

It looks like an improved version of the withObservationTracking function will be available in the near future, making it possible to more easily bind view models to UIKit objects (see example below). The lifetime of the observation can be controlled using ObservationTracking.Token. I like it.

Pull request in the swiftlang/swift repository - https://github.com/swiftlang/swift/pull/86719
Proposal - https://github.com/swiftlang/swift-evolution/blob/main/proposals/0506-advanced-observation-tracking.md

#swift

I think we really need the ability to report AI-generated non-sense and to flag AI-generated responses on stackoverflow as "AI-generated".

I don't blame those who write such responses. But in large numbers, it's very harmful to the developer community, especially to beginners.

#ai #swift

About Swift and Relax diagnostics for pointer arguments to C functions (SE-0324).

In my opinion, SE-0324 is often overlooked or underestimated. But it significantly simplifies working with the C API thanks to implicit pointer conversions. For example, it's acceptable in many cases to pass an argument of type 'UnsafeRawPointer' to a C function. Before SE-0324, we were required to use 'assumingMemoryBound(to:)' (see example below).

Post continues below.

#swift

About Swift and the upcoming async defer blocks (SE-0493) with cancellation shields (SE-0504).

If they don't change the cancellation shields API, the example below will likely become a common pattern for asynchronous resource clean-up. And we'll say goodbye to '''try await Task { try await cleanup() }.value'''.

I'm not sure about the name 'withCancellationShield' though. But in any case, I think it's gonna be a pretty significant improvement.

#swift

About XML and HTML parsing.

I've now accumulated a lot of code that could be contributed as an SPM library for XML/HTML parsing. See below for a simple example of how I currently parse an HTML file loaded into Data. The 'query' and 'subscript' functions accept an XPath string as a parameter.

What do you think?

What do you usually use in your projects for XML parsing?

#swift #xml #html #xpath

A few thoughts to make UIKit API more friendly

Since the release of SwiftUI, I can't stop wondering why we still configure view objects by repeating their names (see Option A below). This code could have been improved by borrowing SwiftUI's syntax (see Option B below). There's even at least one implementation of this approach - chris-swift-dev/UIKit-Modifiers. But I wouldn't use it, because...

Post continues below.

#swift #uikit #ios

Respect Locale when converting user-entered Strings to Decimal

Assuming a fixed decimal separator (for example, a dot) when converting user-entered strings to Decimal can cause silent value changes: users in different locales may use commas as the decimal separator (see example below).

In my experience, this is one of the most common bugs in financial applications.

Always parse using the user's current locale and test your app with multiple region formats.

#ios #swift

About Notification center messages (SF-0011)

Great changes to the NotificationCenter API. Now, instead of the abstract Notification, we can define a Sendable type and use it to post and observe messages. The message type must conform to MainActorMessage or AsyncMessage protocol. The first is for time-critical messages. The second is not tied to the main thread and supports AsyncSequence (see examples below).

Post continues below.

#swift

About Xcode 26 and "Generate String Catalog Symbols" setting.

In Xcode 26, Apple added the ability to generate symbols for localized strings. It works almost in the same way as the tools we've been using for 10 years - Rswift and SwiftGen. To use this feature, we need to enable the build setting "Generate String Catalog Symbols" and migrate from Strings to String Catalogs (if this wasn't done before).

WWDC link - https://developer.apple.com/videos/play/wwdc2025/225/?time=820

#xcode #swift #localization

About Swift 6.2 and SE-0463.

Apple has actually fixed one of the most painful problems in "Strict Concurrency Checking" (see examples below). Starting with Swift 6.2, Objective C completion handler parameters are @Sendable by default. Thanks to @mattiem for mentioning SE-0463.

#swift