Snapp Mobile iOS Newsletter

Issue 18 • November 29, 2024

Hi again!

How many custom implementations of a networking client built on top of URLSession are out there? No one knows for sure, but it’s the feature we’ve seen the most variations of across the projects we’ve worked on. This week, we have a mini-series of articles that look at building such a client from scratch in an attempt to discover the complexity around it and to come up with some useful additions.

We also look at using Apple’s writing tools with SwiftUI, detecting faces with the Vision framework, tweaking the now-built-in version of SwiftFormat in Xcode, and more.

Have fun with this week’s mixture!

Swift

How to keep Date’s microseconds precision in Swift

Swift’s DateFormatter is very handy when you have to convert Date objects from and to String, but it has one known caveat: it loses microsecond precision. This may be problematic in cases where you rely on the date to drive a specific behavior. This article explains how to get the precision back for the cases it’s important (which, honestly, is pretty much always).

Working with Natural Language framework

NaturalLanguage is one of the lesser-known frameworks that Apple ships with its iOS SDK. It has some interesting tools for analyzing and processing text—you can use it to detect the language of a piece of text, find the similarities between two strings, extract addresses from free-form text, etc. This article looks at practical applications of the framework in different scenarios.

The perfect iOS networking layer does not exist - Part 1

As we said in the intro, custom networking is something we had to deal with in most of the projects we have worked on. URLSession is great and has everything we need, but its API often results in boilerplate. This series of articles looks at building a networking layer from scratch with the goal of having a layer that is extendable, testable, mockable, and stub-able :) The first part takes care of the “extendable” part of the promise.

The perfect iOS networking layer does not exist - Part 2

The second part focuses on making the networking layer testable, mockable, and stub-able. We like the use of URLProtocol to mock network requests and stub responses, as it opens up so many possibilities in testing. In our opinion, that feature alone is worth going through the article.

Xcode

Swift Format in Xcode

This article is how we learned that Xcode 16 ships with a built-in copy of SwiftFormat now. SwiftFormat is driven by the Swift working group (you can find the swiftlang/swift-format repository here), and having it integrated with Xcode means that we can utilize it to ensure the entire team works with the same coding style. Learn how with this article.

UI/UX

Detecting faces in images with the Vision framework

If you’ve ever worked with the iPhone camera, chances are that you’ve interacted with the Vision framework. It’s an extremely useful one, packed with features that allow you to do object tracking and recognition that can be extended with custom ML models. It also ships with a few built-in models for detecting a barcode, QR code, human body, or human face from the camera feed or in a still image. This article gets you up and running, using the face detection feature as an example.

Exploring Apple Intelligence: Writing Tools

AppleIntelligence is something we are going to dig into more and more in this newsletter. This time, we’re looking at how to integrate one of its highlighted features—the writing tools—with SwiftUI. Writing tools allow you to “assist your users in composing, editing, and refining their writing seamlessly,” as this article states.

Data

Using Transactions Instead of Save in SwiftData and Core Data

SwiftData’s transaction method is something that’s been introduced with iOS 17. It allows you to queue up multiple inserts, changes, and deletes and apply them to persistent storage in one go. Applications using SwiftData or CoreData will surely benefit from utilizing it as a step forward in optimizing performance.