Digest: Apple Silicon, Airbnb Goes to SwiftUI, Strings Catalog
- #M3 chip
- #SwiftUI
• 6 min read
Corners too rounded? Apple M3 chips. Airbnb takes on SwiftUI. The XCTest update we've been waiting for 10 years. And the new Strings Catalogs.
Read till the end, and I'll recommend a list of very useful resources to learn even more.
The secret formula for Apple's rounded corners
You've probably heard that Apple uses more rounding than other companies.
The squircle
Perhaps designers have approached you saying that this rounded corner catches the eye and that a continuous type should be added.
But today, it's not entirely about that. It's about why Apple devices all have these rounded corners and why some shapes are softer than others.
Besides the obvious fact that sharp-edged objects can harm you, there’s a deeper explanation from neuroscience.
When a person looks at an object with sharp corners, the amygdala in the brain, responsible for fear, gets activated. Hence, people are more inclined to choose soft shapes.
But how do you determine the right radius? Designer Naoto Fukasawa discovered that the closer an object is to the body, the bigger rounding it should have.
AirPods and Apple Watch have a very rounded shape. The iPhone is less rounded, but still more squished than the iPad and MacBook. And large home appliances typically have a very minimal rounding.
That’s an interesting Apple fact for you.
The new M3 chip
Following the spooky theme of Halloween, Apple held its first-ever nighttime presentation on October 30. Dubbed the 'Scary Fast' special event, it introduced the new family of M3 chips that use 3-nanometer technology and claim a giant leap in GPU performance. In addition to the updated MacBook Pro and iMac equipped with the latest chips, Apple also announced the new Space Black finish for MacBook Pro.
Another scary fact: the entire presentation was shot on iPhone and Apple provided a rare behind-the-scenes look.
Testing
Point-Free is on fire releasing new libraries and updates. And lately, the team worked on testing.
First, we got an update to the snapshot testing library. Snapshot tests are not limited to images, they can be also applied to text. For example, to check how an object converts to JSON. Previously, the test result was generated in a separate file, which wasn’t very convenient. Now, it’s displayed directly in Xcode!
Second, there’s a new library for macro testing. Apple already had a similar tool – the assertMacroExpansion method in Swift Syntax that they use internally. The problem with that is having to manually write the code with the macro and what it expands to. But now, folks from Point-Free managed to combine snapshot tests and macros. As a result, you only need to write the code with the macro, run the tests, and get the generated macro expansion right in the code of that test.
Unlocking SwiftUI at Airbnb
Airbnb is gradually adopting SwiftUI.
Back in 2016, they developed their framework for declarative UI. So, they have some expertise in this area.
When SwiftUI was released in 2019, it had limited features, so the team wasn't in a hurry to migrate. Now that the API has become fairly stable, Airbnb has finally decided to switch.
The transition will happen in three phases: from building specific independent components, to creating full screens, and ultimately developing features using multiple screens. Currently, the company is in the second stage.
To move to the third phase, the team wants to see a more flexible navigation than what’s currently available.
Among the interesting findings, the Airbnb team noted fewer lines of code. Even at the start of the experiment, UI-related code was reduced by a factor of six! Meanwhile, the performance retained the UIKit levels. There were occasional overhead reports when using UIHostingController. But most importantly, developers were satisfied with code-writing.
77% of engineers stated they feel more productive with SwiftUI.
Of course, there are still problems. SwiftUI doesn't have ALL the features present in UIKit. Features that do exist are only available in the latest iOS, so you have to wait for another year to start using them. Or you need to develop their implementations for older systems. But in a year and a half, the iOS app already has over 500 views and about 200 screens.
swift-testing
An unexpected and cool update. The XCTest framework has been around for 10 years and has seen little updates, but … Apple is developing a replacement for this framework.
Here's what a test might look like with the new API:
Macro test: the first parameter is the test name and the second one specifies when this test should run.
Following that is a standard function where the macro expect is invoked. This can either be an independent function or part of a Suit, defined by a relevant macro.
To me, it looks significantly cleaner. No need to choose a notation to describe the test name; you can simply write a description. All assertions have now been unified under the single expect macro. Because of this, tests appear simpler, and the error message is more understandable.
What are the rules and how was the API designed? Find out the vision behind the new framework on its GitHub page. It already provides Documentation on test creation and migration from XCTest.
Of course, this is still in early development, and the API may change.
Strings catalog
Xcode 15 added new Strings Catalogs to streamline translations.
Long are the days of separate storage for regular strings and strings that contain plurals. Additionally, it offers a plethora of checks, should you modify a value.
At runtime, the Strings Catalog is compiled into the old format, so you can use it with any system version.
The only odd thing is that Apple didn’t implement constant generation as they did for xcasset. They made it for images and colors, but not for strings? If you're accustomed to generating strings using SwiftGen or R.swift, unfortunately, you cannot currently do it. An open issue on GitHub has been pending since WWDC.
But wait! Somebody found a way to implement generation! The article’s author managed to do it in a super easy way, using SPM plugins. Hence, you can add it both in SPM and in the xcodeproj in build settings.
Conferences
Autumn is always the season of Apple developers gatherings. And immediately three reputable conferences have released their recordings: NSSpain, Pragma Conference, and Swift Connection. They have presentations on almost every topic: VisionOS, macros, animations, architectures, testing, and even metal.
I’m sure there's something for everyone in there. So, save these recordings to watch during the New Year holidays.
Resources
🔗 Promised links:
- Unlocking SwiftUI at Airbnb
- Taking your Strings Catalogs to the Next Level
- A New Approach to Testing in Swift
- Testing framework documentation
- A New API Direction for Testing in Swift
- A new tool for testing macros in Swift
- The secret formula for Apple's rounded corners