From 4000dc3650372179ce4287850a9bca8743e8b788 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Sat, 18 Feb 2023 22:51:44 +0100 Subject: [PATCH] Switch to targeted Swift concurrency warnings + fix them --- IceCubesApp.xcodeproj/project.pbxproj | 2 ++ Packages/Models/Sources/Models/Account.swift | 6 +++--- .../Models/Sources/Models/Alias/HTMLString.swift | 2 +- .../Models/Sources/Models/Alias/ServerDate.swift | 2 +- Packages/Models/Sources/Models/Emoji.swift | 2 +- Packages/Models/Sources/Models/Instance.swift | 14 +++++++------- .../Models/Sources/Models/InstanceSocial.swift | 4 ++-- Packages/Models/Sources/Models/OauthToken.swift | 2 +- Packages/Models/Sources/Models/ServerFilter.swift | 8 ++++---- Packages/Models/Sources/Models/Status.swift | 2 +- Packages/Network/Sources/Network/Client.swift | 6 +++--- .../Sources/Network/Endpoint/Accounts.swift | 4 ++-- .../Sources/Network/Endpoint/Endpoint.swift | 2 +- .../Sources/Network/Endpoint/ServerFilters.swift | 2 +- .../Sources/Network/Endpoint/Statuses.swift | 6 +++--- 15 files changed, 33 insertions(+), 31 deletions(-) diff --git a/IceCubesApp.xcodeproj/project.pbxproj b/IceCubesApp.xcodeproj/project.pbxproj index 3410df11..823d5498 100644 --- a/IceCubesApp.xcodeproj/project.pbxproj +++ b/IceCubesApp.xcodeproj/project.pbxproj @@ -1184,6 +1184,7 @@ SUPPORTS_MACCATALYST = NO; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_STRICT_CONCURRENCY = targeted; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; @@ -1236,6 +1237,7 @@ SUPPORTS_MACCATALYST = NO; SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_STRICT_CONCURRENCY = targeted; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; diff --git a/Packages/Models/Sources/Models/Account.swift b/Packages/Models/Sources/Models/Account.swift index a435518f..d68f4279 100644 --- a/Packages/Models/Sources/Models/Account.swift +++ b/Packages/Models/Sources/Models/Account.swift @@ -1,6 +1,6 @@ import Foundation -public final class Account: Codable, Identifiable, Equatable, Hashable { +public final class Account: Codable, Identifiable, Equatable, Hashable, Sendable { public static func == (lhs: Account, rhs: Account) -> Bool { lhs.id == rhs.id } @@ -9,7 +9,7 @@ public final class Account: Codable, Identifiable, Equatable, Hashable { hasher.combine(id) } - public struct Field: Codable, Equatable, Identifiable { + public struct Field: Codable, Equatable, Identifiable, Sendable { public var id: String { value.asRawText + name } @@ -19,7 +19,7 @@ public final class Account: Codable, Identifiable, Equatable, Hashable { public let verifiedAt: String? } - public struct Source: Codable, Equatable { + public struct Source: Codable, Equatable, Sendable { public let privacy: Visibility public let sensitive: Bool public let language: String? diff --git a/Packages/Models/Sources/Models/Alias/HTMLString.swift b/Packages/Models/Sources/Models/Alias/HTMLString.swift index d169fded..824fde71 100644 --- a/Packages/Models/Sources/Models/Alias/HTMLString.swift +++ b/Packages/Models/Sources/Models/Alias/HTMLString.swift @@ -6,7 +6,7 @@ private enum CodingKeys: CodingKey { case htmlValue, asMarkdown, asRawText, statusesURLs } -public struct HTMLString: Codable, Equatable, Hashable { +public struct HTMLString: Codable, Equatable, Hashable, @unchecked Sendable { public var htmlValue: String = "" public var asMarkdown: String = "" public var asRawText: String = "" diff --git a/Packages/Models/Sources/Models/Alias/ServerDate.swift b/Packages/Models/Sources/Models/Alias/ServerDate.swift index a03e4e78..0d2e240e 100644 --- a/Packages/Models/Sources/Models/Alias/ServerDate.swift +++ b/Packages/Models/Sources/Models/Alias/ServerDate.swift @@ -4,7 +4,7 @@ private enum CodingKeys: CodingKey { case asDate } -public struct ServerDate: Codable, Hashable, Equatable { +public struct ServerDate: Codable, Hashable, Equatable, Sendable { public let asDate: Date public var relativeFormatted: String { diff --git a/Packages/Models/Sources/Models/Emoji.swift b/Packages/Models/Sources/Models/Emoji.swift index 6ef5e3da..47cf8c76 100644 --- a/Packages/Models/Sources/Models/Emoji.swift +++ b/Packages/Models/Sources/Models/Emoji.swift @@ -1,6 +1,6 @@ import Foundation -public struct Emoji: Codable, Hashable, Identifiable, Equatable { +public struct Emoji: Codable, Hashable, Identifiable, Equatable, Sendable { public func hash(into hasher: inout Hasher) { hasher.combine(shortcode) } diff --git a/Packages/Models/Sources/Models/Instance.swift b/Packages/Models/Sources/Models/Instance.swift index 8ab66c24..6900c20b 100644 --- a/Packages/Models/Sources/Models/Instance.swift +++ b/Packages/Models/Sources/Models/Instance.swift @@ -1,19 +1,19 @@ import Foundation -public struct Instance: Codable { - public struct Stats: Codable { +public struct Instance: Codable, Sendable { + public struct Stats: Codable, Sendable { public let userCount: Int public let statusCount: Int public let domainCount: Int } - public struct Configuration: Codable { - public struct Statuses: Codable { + public struct Configuration: Codable, Sendable { + public struct Statuses: Codable, Sendable { public let maxCharacters: Int public let maxMediaAttachments: Int } - public struct Polls: Codable { + public struct Polls: Codable, Sendable { public let maxOptions: Int public let maxCharactersPerOption: Int public let minExpiration: Int @@ -24,12 +24,12 @@ public struct Instance: Codable { public let polls: Polls } - public struct Rule: Codable, Identifiable { + public struct Rule: Codable, Identifiable, Sendable { public let id: String public let text: String } - public struct URLs: Codable { + public struct URLs: Codable, Sendable { public let streamingApi: URL? } diff --git a/Packages/Models/Sources/Models/InstanceSocial.swift b/Packages/Models/Sources/Models/InstanceSocial.swift index 5aa5f380..6d2dc364 100644 --- a/Packages/Models/Sources/Models/InstanceSocial.swift +++ b/Packages/Models/Sources/Models/InstanceSocial.swift @@ -1,7 +1,7 @@ import Foundation -public struct InstanceSocial: Decodable, Identifiable { - public struct Info: Decodable { +public struct InstanceSocial: Decodable, Identifiable, Sendable { + public struct Info: Decodable, Sendable { public let shortDescription: String? } diff --git a/Packages/Models/Sources/Models/OauthToken.swift b/Packages/Models/Sources/Models/OauthToken.swift index 590c3c94..78fb7419 100644 --- a/Packages/Models/Sources/Models/OauthToken.swift +++ b/Packages/Models/Sources/Models/OauthToken.swift @@ -1,6 +1,6 @@ import Foundation -public struct OauthToken: Codable, Hashable { +public struct OauthToken: Codable, Hashable, Sendable { public let accessToken: String public let tokenType: String public let scope: String diff --git a/Packages/Models/Sources/Models/ServerFilter.swift b/Packages/Models/Sources/Models/ServerFilter.swift index 561353d3..d47de752 100644 --- a/Packages/Models/Sources/Models/ServerFilter.swift +++ b/Packages/Models/Sources/Models/ServerFilter.swift @@ -1,17 +1,17 @@ import Foundation -public struct ServerFilter: Codable, Identifiable, Hashable { - public struct Keyword: Codable, Identifiable, Hashable { +public struct ServerFilter: Codable, Identifiable, Hashable, Sendable { + public struct Keyword: Codable, Identifiable, Hashable, Sendable { public let id: String public let keyword: String public let wholeWord: Bool } - public enum Context: String, Codable, CaseIterable { + public enum Context: String, Codable, CaseIterable, Sendable { case home, notifications, `public`, thread, account } - public enum Action: String, Codable, CaseIterable { + public enum Action: String, Codable, CaseIterable, Sendable { case warn, hide } diff --git a/Packages/Models/Sources/Models/Status.swift b/Packages/Models/Sources/Models/Status.swift index be34cfa5..ff5c5b88 100644 --- a/Packages/Models/Sources/Models/Status.swift +++ b/Packages/Models/Sources/Models/Status.swift @@ -18,7 +18,7 @@ public extension Application { } } -public enum Visibility: String, Codable, CaseIterable, Hashable, Equatable { +public enum Visibility: String, Codable, CaseIterable, Hashable, Equatable, Sendable { case pub = "public" case unlisted case priv = "private" diff --git a/Packages/Network/Sources/Network/Client.swift b/Packages/Network/Sources/Network/Client.swift index b83c64cc..8ef59c29 100644 --- a/Packages/Network/Sources/Network/Client.swift +++ b/Packages/Network/Sources/Network/Client.swift @@ -2,14 +2,14 @@ import Foundation import Models import SwiftUI -public class Client: ObservableObject, Equatable, Identifiable, Hashable { +public final class Client: ObservableObject, Equatable, Identifiable, Hashable, @unchecked Sendable { public static func == (lhs: Client, rhs: Client) -> Bool { lhs.isAuth == rhs.isAuth && lhs.server == rhs.server && lhs.oauthToken?.accessToken == rhs.oauthToken?.accessToken } - public enum Version: String { + public enum Version: String, Sendable { case v1, v2 } @@ -26,7 +26,7 @@ public class Client: ObservableObject, Equatable, Identifiable, Hashable { hasher.combine(id) } - public var server: String + public let server: String public let version: Version public private(set) var connections: Set private let urlSession: URLSession diff --git a/Packages/Network/Sources/Network/Endpoint/Accounts.swift b/Packages/Network/Sources/Network/Endpoint/Accounts.swift index 5033615b..6104fdf9 100644 --- a/Packages/Network/Sources/Network/Endpoint/Accounts.swift +++ b/Packages/Network/Sources/Network/Endpoint/Accounts.swift @@ -154,7 +154,7 @@ public enum Accounts: Endpoint { } } -public struct MuteData: Encodable { +public struct MuteData: Encodable, Sendable { public let duration: Int public init(duration: Int) { @@ -162,7 +162,7 @@ public struct MuteData: Encodable { } } -public struct RelationshipNoteData: Encodable { +public struct RelationshipNoteData: Encodable, Sendable { public let comment: String public init(note comment: String) { diff --git a/Packages/Network/Sources/Network/Endpoint/Endpoint.swift b/Packages/Network/Sources/Network/Endpoint/Endpoint.swift index 9bcd2b45..f27ddd2a 100644 --- a/Packages/Network/Sources/Network/Endpoint/Endpoint.swift +++ b/Packages/Network/Sources/Network/Endpoint/Endpoint.swift @@ -1,6 +1,6 @@ import Foundation -public protocol Endpoint { +public protocol Endpoint: Sendable { func path() -> String func queryItems() -> [URLQueryItem]? var jsonValue: Encodable? { get } diff --git a/Packages/Network/Sources/Network/Endpoint/ServerFilters.swift b/Packages/Network/Sources/Network/Endpoint/ServerFilters.swift index 055870c5..7cc6d89a 100644 --- a/Packages/Network/Sources/Network/Endpoint/ServerFilters.swift +++ b/Packages/Network/Sources/Network/Endpoint/ServerFilters.swift @@ -48,7 +48,7 @@ public enum ServerFilters: Endpoint { } } -public struct ServerFilterData: Encodable { +public struct ServerFilterData: Encodable, Sendable { public let title: String public let context: [ServerFilter.Context] public let filterAction: ServerFilter.Action diff --git a/Packages/Network/Sources/Network/Endpoint/Statuses.swift b/Packages/Network/Sources/Network/Endpoint/Statuses.swift index f381c7d6..ce705db6 100644 --- a/Packages/Network/Sources/Network/Endpoint/Statuses.swift +++ b/Packages/Network/Sources/Network/Endpoint/Statuses.swift @@ -91,7 +91,7 @@ public enum Statuses: Endpoint { } } -public struct StatusData: Encodable { +public struct StatusData: Encodable, Sendable { public let status: String public let visibility: Visibility public let inReplyToId: String? @@ -101,7 +101,7 @@ public struct StatusData: Encodable { public let language: String? public let mediaAttributes: [MediaAttribute]? - public struct PollData: Encodable { + public struct PollData: Encodable, Sendable { public let options: [String] public let multiple: Bool public let expires_in: Int @@ -113,7 +113,7 @@ public struct StatusData: Encodable { } } - public struct MediaAttribute: Encodable { + public struct MediaAttribute: Encodable, Sendable { public let id: String public let description: String? public let thumbnail: String?