Archive for July 18, 2023

Tuesday, July 18, 2023

Creating Dynamic Colors in SwiftUI

Jesse Squires:

Beginning with the introduction of dark mode in iOS 13, colors in iOS are now (optionally) dynamic. You can provide light and dark variants for all colors in your app. However, I was surprised to find that SwiftUI — which also made its first appearance on the platform in iOS 13 — still does not provide any API for creating dynamic colors.

[…]

Of course, you can use Asset Catalogs to define dynamic colors and reference them in SwiftUI, and Xcode 15 makes that easier! But if you need to programmatically initialize dynamic colors in SwiftUI, you are out of luck due to this glaring omission. Instead, you must resort to UIKit and AppKit. So, here’s a helpful extension that accommodates the missing API for all platforms.

Laws of UX

Jon Yablonski (via Hacker News):

Laws of UX is a collection of best practices that designers can consider when building user interfaces.

[…]

The time to acquire a target is a function of the distance to and size of the target.

[…]

The time it takes to make a decision increases with the number and complexity of choices.

[…]

Users spend most of their time on other sites. This means that users prefer your site to work the same way as all the other sites they already know.

[…]

Be liberal in what you accept, and conservative in what you send.

The site itself is not particularly usable, with text not selectable and problems with the back button.

Previously:

ExtensionKit and XPC

Matt Massicotte:

ExtensionKit is a pretty significant new feature of macOS Ventura. But, I wouldn’t be surprised if you didn’t know, as it had a conspicuously quiet introduction. There were no sessions or labs about it during WWDC 2022. I only discovered it because a friend stumbled across the beta documentation and sent it to me.

[…]

At a high-level, you can define extension points in your app, either with or without a UI component. All communication between extension and host goes over XPC, and there’s a bit of infrastructure provided by Apple for discovering available extensions and establishing a connection.

One of the most exciting things ExtensionKit can do is remote views. This is a view that is constructed with SwiftUI and managed within the extension, but displayed within the hosting application. As far as I can tell, this arrangement is totally transparent and supports virtually everything that SwiftUI can do, even animation. Perhaps the only real downside is window/view resizing can sometimes have a little lag.

There is now some documentation for ExtensionKit.

Matt Massicotte:

Being a communication system, all XPC calls can fail. They can fail even if the method does not return an error. And, because of how they can fail, XPC methods do not guarantee that their reply callback will be called. This is extremely important, because that behavior violates the Swift concurrency runtime requirements. XPC calls will hang your tasks when they fail. Because of this, it is unsafe to use this technique in your XPC interfaces.

[…]

This poor fit between XPC and Swift has bothered many others. There are two libraries that look pretty nice for dealing with all this nonsense: SwiftyXPC and SecureXPC. They both offer async/await support, and use Codable for serializing data. Unfortunately, they also both use their own custom communication primitives. That doesn’t work well for us - ExtensionKit requires NSXPCConnection instances.

Christian Tietze:

I want to give a big shout-out to Matt Massicotte of ChimeHQ for dropping another awesome Swift open source package that makes using XPC Swift-ier. I’m really grateful for all the amazing work Matt has been doing and for sharing it with the community.

[…]

So among a ton of other things, here are Matt’s concurrency and XPC related packages (some recently split off of ConcurrencyPlus)[…]

Previously:

eWorld Promotional Mailer

Stephen Hackett:

An anonymous 512 Pixels reader recently mailed me something amazing — a promotional mailer for eWorld, dating back to 1994. In the package was a set of 3.5-inch eWorld 1.0 installer disks, the “Apple Online Service Subscriber Agreement” and an amazing brochure for eWorld.

eWorld was great.