mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Swift 6 Migration (#5733)
* Enable Swift 6.2 with default main actor isolation for the app target Turn on SWIFT_VERSION 6.2, SWIFT_APPROACHABLE_CONCURRENCY and SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor for the ElementX target, matching the NSE and Share Extension (which already use 6.2 without the main actor default). # Conflicts: # ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved * Update the code generation templates for Swift 6 Emit nonisolated/@unchecked Sendable mocks and nonisolated string enums, and mark async mock methods @concurrent so they keep suspending like the real implementations (otherwise intermediate states are unobservable in tests). Includes the regenerated mocks and strings. # Conflicts: # ElementX/Sources/Mocks/Generated/GeneratedMocks.swift * Make the data layer and services nonisolated and Sendable Annotate the value-type models, Rust SDK proxy wrappers, timeline item graph, settings, logging and NSE-shared types as nonisolated, and conform the service protocols to Sendable so their existentials can cross isolation boundaries. These types run off the main actor and no longer inherit the target's default main actor isolation. * Adopt the new isolation across call sites, mocks and signatures Update call sites, closure signatures and mock configuration helpers to match the nonisolated/Sendable data layer, including the main actor isolated mock inits and the @Sendable filter on recentlyVisitedRooms. ^ Conflicts: ^ ElementX/Sources/Services/SecureBackup/SecureBackupController.swift * Remove redundant @MainActor annotations With the app target defaulting to main actor isolation, the explicit @MainActor on view models, coordinators, views and their protocols is no longer required. * Fix concurrency hotspots surfaced by the migration Resolve the room summary main-thread deadlock by moving diff processing onto AsyncStreams, add the SDKListener.onMainActor FIFO bridge for SDK callbacks, hop KVO/timer/UIKit callbacks to the main actor via assumeIsolated, add isolated deinits, and apply the few justified nonisolated(unsafe) escapes for queue-confined Apple APIs. * Fix the unit tests for Swift 6 concurrency Hop the waitForConfirmation body onto the caller's actor (Swift Testing runs confirmation closures off-actor), and adjust the affected suites and async signatures. * offload diffs on concurrent threads instead of main actor * make room info protocols sendable * use a task group for fetching data so that everything runs concurrently in the TextRoomTimelineView when getting the preview. * use the generic onMainActor implementation, which already makes a stream and send the continuation on the main actor. * small pr comments issues being addressed * update enterprise * Update StaticCode to 1.1.0 and specify the required Swift isolation. * fix ElementCallServiceTests * update enterprise * re-generate mocks * update enterprise * enterprise new code conformed to swift 6 --------- Co-authored-by: Doug <douglase@element.io>
This commit is contained in:
@@ -67,7 +67,7 @@ struct FullscreenDialog<Content: View, BottomContent: View>: View {
|
||||
}
|
||||
|
||||
/// A layout where the content scrolls with the bottom content overlaid. Used with regular font sizes.
|
||||
@MainActor var standardLayout: some View {
|
||||
var standardLayout: some View {
|
||||
GeometryReader { geometry in
|
||||
ScrollView {
|
||||
VStack(spacing: 0) {
|
||||
|
||||
@@ -13,10 +13,9 @@ extension View {
|
||||
/// Reads the frame of the view and stores it in the `frame` binding.
|
||||
/// - Parameters:
|
||||
/// - frame: a `CGRect` binding
|
||||
/// - coordinateSpace: the coordinate space of the frame.
|
||||
func readFrame(_ frame: Binding<CGRect>, in coordinateSpace: CoordinateSpace = .local) -> some View {
|
||||
func readFrame(_ frame: Binding<CGRect>) -> some View {
|
||||
onGeometryChange(for: CGRect.self) { geometry in
|
||||
geometry.frame(in: coordinateSpace)
|
||||
geometry.frame(in: .local)
|
||||
} action: { newValue in
|
||||
frame.wrappedValue = newValue
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
import Foundation
|
||||
|
||||
/// Represents a specific portion of the ViewState that can be bound to with SwiftUI's [2-way binding](https://developer.apple.com/documentation/swiftui/binding).
|
||||
@MainActor
|
||||
protocol BindableState {
|
||||
/// The associated type of the Bindable State. Defaults to Void.
|
||||
associatedtype BindStateType = Void
|
||||
|
||||
@@ -16,7 +16,6 @@ import Foundation
|
||||
/// a specific portion of state that can be safely bound to.
|
||||
/// If we decide to add more features to our state management (like doing state processing off the main thread)
|
||||
/// we can do it in this centralised place.
|
||||
@MainActor
|
||||
class StateStoreViewModel<State: BindableState, ViewAction> {
|
||||
/// For storing subscription references.
|
||||
///
|
||||
@@ -57,7 +56,6 @@ class StateStoreViewModel<State: BindableState, ViewAction> {
|
||||
/// It provides a nice layer of consistency and also safety. As we are not passing the `ViewModel` to the view directly, shortcuts/hacks
|
||||
/// can't be made into the `ViewModel`.
|
||||
@dynamicMemberLookup
|
||||
@MainActor
|
||||
final class Context: ObservableObject {
|
||||
fileprivate weak var viewModel: StateStoreViewModel?
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ import Observation
|
||||
/// a specific portion of state that can be safely bound to.
|
||||
/// If we decide to add more features to our state management (like doing state processing off the main thread)
|
||||
/// we can do it in this centralised place.
|
||||
@MainActor
|
||||
class StateStoreViewModelV2<State: BindableState, ViewAction> {
|
||||
/// For storing subscription references.
|
||||
///
|
||||
@@ -59,7 +58,6 @@ class StateStoreViewModelV2<State: BindableState, ViewAction> {
|
||||
/// It provides a nice layer of consistency and also safety. As we are not passing the `ViewModel` to the view directly, shortcuts/hacks
|
||||
/// can't be made into the `ViewModel`.
|
||||
@dynamicMemberLookup
|
||||
@MainActor
|
||||
@Observable final class Context {
|
||||
fileprivate weak var viewModel: StateStoreViewModelV2?
|
||||
|
||||
|
||||
@@ -230,16 +230,24 @@ private struct LoadableImageContent<TransformerView: View, PlaceholderView: View
|
||||
|
||||
// MARK: - ImageDataProvider
|
||||
|
||||
var cacheKey: String {
|
||||
nonisolated var cacheKey: String {
|
||||
mediaSource.url.absoluteString
|
||||
}
|
||||
|
||||
func data(handler: @escaping (Result<Data, Error>) -> Void) {
|
||||
guard case let .gifData(data) = contentLoader.content else {
|
||||
nonisolated func data(handler: @escaping (Result<Data, Error>) -> Void) {
|
||||
// Kingfisher isn't annotated but invokes the provider on the main thread.
|
||||
let gifData = MainActor.assumeIsolated { () -> Data? in
|
||||
guard case let .gifData(data) = contentLoader.content else {
|
||||
return nil
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
guard let gifData else {
|
||||
fatalError("Shouldn't reach this point without any gif data")
|
||||
}
|
||||
|
||||
handler(.success(data))
|
||||
handler(.success(gifData))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,7 +287,6 @@ private class ContentLoader: ObservableObject {
|
||||
self.mediaProvider = mediaProvider
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func load() async {
|
||||
if isGIF {
|
||||
if case let .success(data) = await mediaProvider?.loadImageDataFromSource(mediaSource) {
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
struct RoomInviterDetails: Equatable {
|
||||
let id: String
|
||||
let displayName: String?
|
||||
|
||||
@@ -9,7 +9,6 @@ import Compound
|
||||
import SwiftUI
|
||||
|
||||
struct ToolbarButton: View {
|
||||
@MainActor
|
||||
enum Role {
|
||||
static let cancel = Role.cancel(title: L10n.actionCancel)
|
||||
static let done = Role.confirm(title: L10n.actionDone)
|
||||
|
||||
Reference in New Issue
Block a user