Skip to content

Commit

Permalink
Fix Xcode 16.2 concurrency issues
Browse files Browse the repository at this point in the history
  • Loading branch information
philippzagar committed Dec 9, 2024
1 parent f875144 commit 0b1a05c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ public struct HorizontalGeometryReader<Content: View>: View {
}
)
.onPreferenceChange(WidthPreferenceKey.self) { width in
self.width = width
// The `onPreferenceChange` view modfier now takes a `@Sendable` closure, therefore we cannot capture `@MainActor` isolated properties
// on the `View` directly anymore: https://developer.apple.com/documentation/swiftui/view/onpreferencechange(_:perform:)?changes=latest_minor
// However, as the `@Sendable` closure is still run on the MainActor (at least in my testing on 18.2 RC SDKs), we can use `MainActor.assumeIsolated`
// to avoid scheduling a `MainActor` `Task`, which could delay execution and cause unexpected UI behavior.
MainActor.assumeIsolated {
self.width = width
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion Tests/UITests/TestApp/ViewsTests/CanvasTestView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ struct CanvasTestView: View {
}
.navigationBarTitleDisplayMode(.inline)
.onPreferenceChange(CanvasView.CanvasSizePreferenceKey.self) { size in
self.receivedSize = size
// See `HorizontalGeometryReader.swift`
MainActor.assumeIsolated {
self.receivedSize = size
}
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions Tests/UITests/UITests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,3,7";
};
name = Debug;
Expand Down Expand Up @@ -606,7 +606,7 @@
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,3,7";
};
name = Release;
Expand All @@ -629,7 +629,7 @@
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
TEST_TARGET_NAME = TestApp;
};
Expand All @@ -652,7 +652,7 @@
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
TEST_TARGET_NAME = TestApp;
};
Expand Down Expand Up @@ -753,7 +753,7 @@
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,3,7";
};
name = Test;
Expand All @@ -776,7 +776,7 @@
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
TEST_TARGET_NAME = TestApp;
};
Expand Down

0 comments on commit 0b1a05c

Please sign in to comment.