I'm using the release version of Xcode 13.2 (13C90) downloaded from the Developer Website (not the App Store) but also observed this behavior in Beta 2 and the release candidate.
Steps to reproduce
- Create a brand new Swift UI app and initialize an actor. This is the entire diff of my app from the default project:
diff --git a/TestApp/ContentView.swift b/TestApp/ContentView.swift
index 8eb8cb1..2367c25 100644
--- a/TestApp/ContentView.swift
+++ b/TestApp/ContentView.swift
@@ -8,14 +8,16 @@
import SwiftUI
struct ContentView: View {
+ @ObservedObject var testState: TestState
+
var body: some View {
Text("Hello, world!")
.padding()
}
}
diff --git a/TestApp/TestAppApp.swift b/TestApp/TestAppApp.swift
index bccc88e..b5b575f 100644
--- a/TestApp/TestAppApp.swift
+++ b/TestApp/TestAppApp.swift
@@ -11,7 +11,7 @@ import SwiftUI
struct TestAppApp: App {
var body: some Scene {
WindowGroup {
- ContentView()
+ ContentView(testState: TestState())
}
}
}
diff --git a/TestApp/TestState.swift b/TestApp/TestState.swift
index 3b3fb0e..b11c044 100644
--- a/TestApp/TestState.swift
+++ b/TestApp/TestState.swift
@@ -6,3 +6,13 @@
//
import Foundation
+
+class TestState: ObservableObject {
+ init() {
+ let testActor = TestActor()
+ }
+}
+
+actor TestActor {
+
+}
-
Set the deployment target to 14.0 (I've experimented with different versions up to 14.7 with no change in behavior).
-
Launch the app on an iOS 14 device (I've seen this issue on devices running 14.4.2 and 14.8.1).
-
Terminate the app (either via Xcode or swiping up in the list of apps).
-
Attach to the process via Debug > Attach to Process by PID or Name (so the error message can be observed).
-
Relaunch the app on the phone.
Expected behavior
App launches correctly on both initial and subsequent launches.
Observed behavior
After the initial successful launch (directly from Xcode), all subsequent launches of the app crash immediately, with Xcode highlighting the line "let testActor = TestActor()" with the following error:
Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)
Unfortunately I can't seem to get any additional information (happy for any tips) but here are some screenshots of what I see in Xcode:
If I comment out the line that initializes the actor, the app no longer crashes. The crash will also happen when the app is distributed via TestFlight immediately on launch. Some things I've tried (most of these don't necessarily make sense, but I was trying anything that seemed to work ):
-
Adding
-Wl,-weak-lswift_Concurrency -Wl,-rpath,/usr/lib/swift
to linker flags. The release notes say this is specifically for an error around Concurrency library not loading, but I'm not seeing that specific error / this didn't fix anything. -
Disabling bitcode
-
Manually adding the Concurrency library in the "Link Binary With Libraries" Build Phase section.
Are there any other debugging steps I can take? I'm running the latest macOS (12.1) on a brand new laptop (MacBook Pro M1 Max) and seeing this issue with a brand new project across a number of devices. I haven't seen other reports of this issue so I'm slightly baffled but happy to try anything and everything as this is a large blocker for an app we're trying to test.
Thanks!
PS. The async / await and actor functionality is incredible and has already addressed a number of bugs, but many of our users are on iOS 14.