Weird Swift concurrency warnings when building Swift project with Xcode 14.3

When building our project in Xcode 14.3, numerous weird warnings do not seem to be related to our code:

<unknown>:0: warning: cannot form key path that captures non-sendable type 'KeyPath<AttributeScopes.FoundationAttributes, AttributeScopes.FoundationAttributes.DateFieldAttribute>'
Swift.KeyPath:1:14: note: generic class 'KeyPath' does not conform to the 'Sendable' protocol
public class KeyPath<Root, Value> : PartialKeyPath<Root> {
             ^
<unknown>:0: warning: cannot form key path that captures non-sendable type 'KeyPath<AttributeScopes.UIKitAttributes, AttributeScopes.UIKitAttributes.FontAttribute>'
Swift.KeyPath:1:14: note: generic class 'KeyPath' does not conform to the 'Sendable' protocol
public class KeyPath<Root, Value> : PartialKeyPath<Root> {
             ^
<unknown>:0: warning: cannot form key path that captures non-sendable type 'KeyPath<AttributeScopes.UIKitAttributes, AttributeScopes.UIKitAttributes.FontAttribute>'
Swift.KeyPath:1:14: note: generic class 'KeyPath' does not conform to the 'Sendable' protocol
public class KeyPath<Root, Value> : PartialKeyPath<Root> {
             ^

It is just a tiny portion of warnings we wee in build results each time. Hundreds of them make it impossible to spot other warnings that these logs might obscure.

We can't figure out where they come from, what triggers them, and, more importantly, how to eliminate or at least suppress them.

Can anyone suggest any workaround or give a clue on how to fix these warnings?

When building our project in Xcode 14.3, numerous weird warnings do not seem to be related to our code

If you create a new test project from the built-in template that best matches your real project — for example, if you’re building an iOS app using UIKit, choose iOS > App and select Storyboard as your interface — does it have the same problem?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hello Quinn!

Thank you for your response.

I cannot reproduce these warnings on a test project, which leads to the obvious conclusion that it is somehow related to the current code or project configuration.

Can you give any clue or hint where to look for the source of those compiler warnings, or how can we narrow down the search?

Thank you!

Well, the first thing to check is the state of the Swift Concurrency Checking (SWIFT_STRICT_CONCURRENCY) build setting on both your new and old projects.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I set SWIFT_STRICT_CONCURRENCY to Complete, and the only warnings I get are the ones regarding _preview and _platform:

.../SwiftUI.PreviewProvider:4:34: Main actor-isolated static property '_previews' cannot be used to satisfy nonisolated protocol requirement

.../SwiftUI.PreviewProvider:5:34: Main actor-isolated static property '_platform' cannot be used to satisfy nonisolated protocol requirement

.../SwiftUI.PreviewProvider:4:34: Main actor-isolated static property '_previews' cannot be used to satisfy nonisolated protocol requirement

.../SwiftUI.PreviewProvider:5:34: Main actor-isolated static property '_platform' cannot be used to satisfy nonisolated protocol requirement

I've seen these warnings in my main project, but as far as I know, they do not appear when building with Xcode 15.

And still, no warnings related to key paths, as shown in the original post.

OK.

In your main project, do you have multiple targets? Are the warnings related to one specific target? Or do you get the same warnings over and over again for each target?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Yes, we have multiple targets in our project. Specifically: two apps, two frameworks, widget extensions, and a bunch of test bundles.

These warnings are not unique to a specific target and occur in various places in the project.

These warnings are not unique to a specific target and occur in various places in the project.

That means it’s a project setting rather than a setting on a specific target.

So:

  • You have your main project that generates these warnings with Xcode 14.3.

  • You have a test project that doesn’t, again with Xcode 14.3.

  • The value of SWIFT_STRICT_CONCURRENCY is the same on both.

Right?

Given that, it’s time for some good ol’ differential debugging. Take your main project and start removing stuff until it’s as simple as your test project. So, start by removing targets until you have just one app target, then remove source code in that target until you’re down to a single source file that looks like your test project. As you go, keep checking to ensure that the warnings still occur.

After that, start comparing build settings, focusing on the project build settings.

Eventually you should find the thing that’s triggering the issue, or end up with two projects that are identical in which case… well… the mystery deepens (-:


Oh, but before you do that, move your project to a completely new machine and verify that the problem still happens there. That rules out any environmental factors. If you don’t have a different Mac to try it on, you might be able to use a VM for this. And if you don’t have either of those, a good approximation is to create a new user account on your main Mac.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Weird Swift concurrency warnings when building Swift project with Xcode 14.3
 
 
Q