From 597c66a85e82e17cd567b7383875a630e142040c Mon Sep 17 00:00:00 2001 From: Maksym Bilan <> Date: Sun, 4 Aug 2024 11:25:10 +0300 Subject: [PATCH 1/3] Swift 6 migration --- Patchcord.xcodeproj/project.pbxproj | 8 ++++++-- Patchcord/Core/App.swift | 10 +++++----- Patchcord/Core/Generics.swift | 2 +- Patchcord/Core/Store.swift | 2 +- .../Middlewares/Connection/ConnectionMiddleware.swift | 2 +- .../Middlewares/CoreData/CoreDataMiddleware.swift | 2 +- Patchcord/Middlewares/Logger/LoggerMiddleware.swift | 2 +- .../Screens/Connection/ConnectionStateReducer.swift | 2 +- Patchcord/Screens/History/HistoryStateReducer.swift | 2 +- Patchcord/States/SceneStateReducer.swift | 2 +- Patchcord/States/ScreenStateReducer.swift | 2 +- 11 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Patchcord.xcodeproj/project.pbxproj b/Patchcord.xcodeproj/project.pbxproj index a41ae6d..530abc2 100644 --- a/Patchcord.xcodeproj/project.pbxproj +++ b/Patchcord.xcodeproj/project.pbxproj @@ -594,6 +594,8 @@ ONLY_ACTIVE_ARCH = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_STRICT_CONCURRENCY = complete; + SWIFT_VERSION = ""; }; name = Debug; }; @@ -646,6 +648,8 @@ MTL_FAST_MATH = YES; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OPTIMIZATION_LEVEL = "-O"; + SWIFT_STRICT_CONCURRENCY = complete; + SWIFT_VERSION = ""; }; name = Release; }; @@ -683,7 +687,7 @@ SUPPORTS_MACCATALYST = NO; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 1; }; name = Debug; @@ -722,7 +726,7 @@ SUPPORTS_MACCATALYST = NO; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 1; }; name = Release; diff --git a/Patchcord/Core/App.swift b/Patchcord/Core/App.swift index 8cdae66..de342e3 100644 --- a/Patchcord/Core/App.swift +++ b/Patchcord/Core/App.swift @@ -18,11 +18,11 @@ let connection = ConnectionMiddleware() let logger = LoggerMiddleware() /// Redux store ♻️ -let store = Store(initial: SceneState(), - reducer: SceneState.reducer, - middlewares: [connection.middleware, - coreData.middleware, - logger.middleware]) +@MainActor let store = Store(initial: SceneState(), + reducer: SceneState.reducer, + middlewares: [connection.middleware, + coreData.middleware, + logger.middleware]) /// App Instance 📱 @main diff --git a/Patchcord/Core/Generics.swift b/Patchcord/Core/Generics.swift index eba0cbe..76eee5e 100644 --- a/Patchcord/Core/Generics.swift +++ b/Patchcord/Core/Generics.swift @@ -8,7 +8,7 @@ import Foundation import Combine -protocol Action { +@preconcurrency protocol Action { var animated: Bool { get } } diff --git a/Patchcord/Core/Store.swift b/Patchcord/Core/Store.swift index 8532699..fd1e491 100644 --- a/Patchcord/Core/Store.swift +++ b/Patchcord/Core/Store.swift @@ -9,7 +9,7 @@ import Combine import SwiftUI /// Redux store ♻️ -final class Store: ObservableObject { +final class Store: ObservableObject, @unchecked Sendable { var isEnabled = true @Published private(set) var state: State diff --git a/Patchcord/Middlewares/Connection/ConnectionMiddleware.swift b/Patchcord/Middlewares/Connection/ConnectionMiddleware.swift index 983ad2b..92b7c2b 100644 --- a/Patchcord/Middlewares/Connection/ConnectionMiddleware.swift +++ b/Patchcord/Middlewares/Connection/ConnectionMiddleware.swift @@ -10,7 +10,7 @@ import SwiftUI import NDT7 /// Middleware that pefrorms all connection tests. Like speed test, ping, fetching public IP, etc 📡🛰 -class ConnectionMiddleware { +class ConnectionMiddleware: @unchecked Sendable { private var connectedStore: Store? private let queue: DispatchQueue private let ipConfig: IPConfig diff --git a/Patchcord/Middlewares/CoreData/CoreDataMiddleware.swift b/Patchcord/Middlewares/CoreData/CoreDataMiddleware.swift index d6da186..4b85294 100644 --- a/Patchcord/Middlewares/CoreData/CoreDataMiddleware.swift +++ b/Patchcord/Middlewares/CoreData/CoreDataMiddleware.swift @@ -9,7 +9,7 @@ import CoreData import Combine /// Middleware that handles all operations with the local database 💾 -final class CoreDataMiddleware { +final class CoreDataMiddleware: @unchecked Sendable { let context: NSManagedObjectContext let testResultsRepository: CoreDataRepository diff --git a/Patchcord/Middlewares/Logger/LoggerMiddleware.swift b/Patchcord/Middlewares/Logger/LoggerMiddleware.swift index c872ba0..197c759 100644 --- a/Patchcord/Middlewares/Logger/LoggerMiddleware.swift +++ b/Patchcord/Middlewares/Logger/LoggerMiddleware.swift @@ -8,7 +8,7 @@ import Combine /// Middleware that logs all states in the console ✍️ -final class LoggerMiddleware { +final class LoggerMiddleware: @unchecked Sendable { func middleware(state: SceneState, action: Action) -> AnyPublisher { let stateDescription = "\(state)".replacingOccurrences(of: "Patchcord.", with: "") diff --git a/Patchcord/Screens/Connection/ConnectionStateReducer.swift b/Patchcord/Screens/Connection/ConnectionStateReducer.swift index 77ac505..a888d89 100644 --- a/Patchcord/Screens/Connection/ConnectionStateReducer.swift +++ b/Patchcord/Screens/Connection/ConnectionStateReducer.swift @@ -9,7 +9,7 @@ import Foundation extension ConnectionState { - static let reducer: Reducer = { state, action in + @MainActor static let reducer: Reducer = { state, action in switch action { case ConnectionStateAction.startTest: return ConnectionState(testState: .started) diff --git a/Patchcord/Screens/History/HistoryStateReducer.swift b/Patchcord/Screens/History/HistoryStateReducer.swift index 9a6dbb5..5d36e9c 100644 --- a/Patchcord/Screens/History/HistoryStateReducer.swift +++ b/Patchcord/Screens/History/HistoryStateReducer.swift @@ -9,7 +9,7 @@ import Foundation extension HistoryState { - static let reducer: Reducer = { state, action in + @MainActor static let reducer: Reducer = { state, action in switch action { case HistoryStateAction.fetchHistory: return HistoryState(isLoading: true, results: []) diff --git a/Patchcord/States/SceneStateReducer.swift b/Patchcord/States/SceneStateReducer.swift index 3f9c21d..a8c56ae 100644 --- a/Patchcord/States/SceneStateReducer.swift +++ b/Patchcord/States/SceneStateReducer.swift @@ -9,7 +9,7 @@ import Foundation extension SceneState { - static let reducer: Reducer = { state, action in + @MainActor static let reducer: Reducer = { state, action in SceneState(screens: state.screens.map { ScreenState.reducer($0, action) }) } diff --git a/Patchcord/States/ScreenStateReducer.swift b/Patchcord/States/ScreenStateReducer.swift index 528c8c8..4ab089d 100644 --- a/Patchcord/States/ScreenStateReducer.swift +++ b/Patchcord/States/ScreenStateReducer.swift @@ -9,7 +9,7 @@ import Foundation extension ScreenState { - static let reducer: Reducer = { state, action in + @MainActor static let reducer: Reducer = { state, action in switch state { case .connection(let state): return .connection(ConnectionState.reducer(state, action)) From f5399a6b9a3d9cf823faae4ae26eb59f918f21ac Mon Sep 17 00:00:00 2001 From: Maksym Bilan <> Date: Sun, 4 Aug 2024 11:27:45 +0300 Subject: [PATCH 2/3] Upgrade project settings --- Patchcord.xcodeproj/project.pbxproj | 6 +++--- .../xcshareddata/xcschemes/Patchcord.xcscheme | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Patchcord.xcodeproj/project.pbxproj b/Patchcord.xcodeproj/project.pbxproj index 530abc2..d9b89c7 100644 --- a/Patchcord.xcodeproj/project.pbxproj +++ b/Patchcord.xcodeproj/project.pbxproj @@ -416,7 +416,7 @@ attributes = { BuildIndependentTargetsInParallel = 1; LastSwiftUpdateCheck = 1400; - LastUpgradeCheck = 1430; + LastUpgradeCheck = 1600; TargetAttributes = { 5023A0AD2854B87D009563B8 = { CreatedOnToolsVersion = 14.0; @@ -575,6 +575,7 @@ DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -636,6 +637,7 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -734,7 +736,6 @@ 5023A0DC2854B87E009563B8 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; @@ -759,7 +760,6 @@ 5023A0DD2854B87E009563B8 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; diff --git a/Patchcord.xcodeproj/xcshareddata/xcschemes/Patchcord.xcscheme b/Patchcord.xcodeproj/xcshareddata/xcschemes/Patchcord.xcscheme index 4221780..4af955d 100644 --- a/Patchcord.xcodeproj/xcshareddata/xcschemes/Patchcord.xcscheme +++ b/Patchcord.xcodeproj/xcshareddata/xcschemes/Patchcord.xcscheme @@ -1,6 +1,6 @@ Date: Sun, 4 Aug 2024 11:29:34 +0300 Subject: [PATCH 3/3] Fixing tests --- Patchcord.xcodeproj/project.pbxproj | 4 ++-- PatchcordTests/ConnectionTests.swift | 2 +- PatchcordTests/Generics/ConnectionMock.swift | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Patchcord.xcodeproj/project.pbxproj b/Patchcord.xcodeproj/project.pbxproj index d9b89c7..0306fb2 100644 --- a/Patchcord.xcodeproj/project.pbxproj +++ b/Patchcord.xcodeproj/project.pbxproj @@ -751,7 +751,7 @@ SUPPORTS_MACCATALYST = NO; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_EMIT_LOC_STRINGS = NO; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 1; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Patchcord.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Patchcord"; }; @@ -775,7 +775,7 @@ SUPPORTS_MACCATALYST = NO; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_EMIT_LOC_STRINGS = NO; - SWIFT_VERSION = 5.0; + SWIFT_VERSION = 6.0; TARGETED_DEVICE_FAMILY = 1; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Patchcord.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Patchcord"; }; diff --git a/PatchcordTests/ConnectionTests.swift b/PatchcordTests/ConnectionTests.swift index 5c119bb..5370a08 100644 --- a/PatchcordTests/ConnectionTests.swift +++ b/PatchcordTests/ConnectionTests.swift @@ -11,7 +11,7 @@ import NDT7 final class ConnectionTests: XCTestCase { - func testStates() { + @MainActor func testStates() { // Initializes the app components let persistance = Persistence(inMemory: true) let connection = ConnectionMock(ipConfig: IPConfigMock()) diff --git a/PatchcordTests/Generics/ConnectionMock.swift b/PatchcordTests/Generics/ConnectionMock.swift index 6a655ae..caba33d 100644 --- a/PatchcordTests/Generics/ConnectionMock.swift +++ b/PatchcordTests/Generics/ConnectionMock.swift @@ -7,7 +7,7 @@ @testable import Patchcord -final class ConnectionMock: ConnectionMiddleware { +final class ConnectionMock: ConnectionMiddleware, @unchecked Sendable { private var latestTest: NDT7TestStub?