diff --git a/Sources/MarkdownUI/Theme/BlockStyle/BlockStyle.swift b/Sources/MarkdownUI/Theme/BlockStyle/BlockStyle.swift index 5dee5ca7..73b3460f 100644 --- a/Sources/MarkdownUI/Theme/BlockStyle/BlockStyle.swift +++ b/Sources/MarkdownUI/Theme/BlockStyle/BlockStyle.swift @@ -37,8 +37,8 @@ import SwiftUI /// ``` /// /// ![](CustomBlockquote) -public struct BlockStyle { - private let body: (Configuration) -> AnyView +public struct BlockStyle : Sendable { + private let body: @Sendable (Configuration) -> AnyView /// Creates a block style that customizes a block by applying the given body. /// - Parameter body: A view builder that returns the customized block. diff --git a/Sources/MarkdownUI/Theme/TextStyle/Styles/FontProperties.swift b/Sources/MarkdownUI/Theme/TextStyle/Styles/FontProperties.swift index 10090cd8..a586c93e 100644 --- a/Sources/MarkdownUI/Theme/TextStyle/Styles/FontProperties.swift +++ b/Sources/MarkdownUI/Theme/TextStyle/Styles/FontProperties.swift @@ -3,7 +3,7 @@ import SwiftUI /// The characteristics of a font. public struct FontProperties: Hashable { /// The font family. - public enum Family: Hashable { + public enum Family: Hashable, Sendable { /// The system font family. case system(Font.Design = .default) @@ -12,7 +12,7 @@ public struct FontProperties: Hashable { } /// The font family variant. - public enum FamilyVariant: Hashable { + public enum FamilyVariant: Hashable, Sendable { /// No variant. Use the current font family. case normal @@ -21,7 +21,7 @@ public struct FontProperties: Hashable { } /// The font caps variant. - public enum CapsVariant: Hashable { + public enum CapsVariant: Hashable, Sendable { /// Don't use a font caps variant. case normal @@ -36,7 +36,7 @@ public struct FontProperties: Hashable { } /// The font digit variant. - public enum DigitVariant: Hashable { + public enum DigitVariant: Hashable, Sendable { /// Don't use a font digit variant. case normal @@ -45,7 +45,7 @@ public struct FontProperties: Hashable { } /// The font style. - public enum Style { + public enum Style: Sendable { /// Don't use a font style. case normal @@ -98,11 +98,11 @@ public struct FontProperties: Hashable { /// The font width. @available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) public var width: Font.Width { - get { (self.widthStorage as? Font.Width) ?? .standard } - set { self.widthStorage = newValue } + get { (self.widthStorage?.base as? Font.Width) ?? .standard } + set { self.widthStorage = AnySendableHashableBox(newValue) } } - private var widthStorage: AnyHashable? + private var widthStorage: AnySendableHashableBox? /// The font size. public var size: CGFloat = Self.defaultSize @@ -187,3 +187,14 @@ extension FontProperties: TextStyle { attributes.fontProperties = self } } + +// A cheap workaround for `AnyHashable` of a `Sendable` not being `Sendable`. +// This is necessary for `widthStorage`. +// TODO: iOS16,macOS13 once minimum deployment target is raised, remove this indirection +fileprivate struct AnySendableHashableBox: Hashable, @unchecked Sendable { + let base: AnyHashable + + init(_ base: V) { + self.base = base + } +} diff --git a/Sources/MarkdownUI/Theme/TextStyle/Styles/FontSize.swift b/Sources/MarkdownUI/Theme/TextStyle/Styles/FontSize.swift index 9b20ae74..b5ee6295 100644 --- a/Sources/MarkdownUI/Theme/TextStyle/Styles/FontSize.swift +++ b/Sources/MarkdownUI/Theme/TextStyle/Styles/FontSize.swift @@ -2,7 +2,7 @@ import Foundation /// A text style that sets the font size. public struct FontSize: TextStyle { - private enum Size { + private enum Size: Sendable { case points(CGFloat) case relative(RelativeSize) } diff --git a/Sources/MarkdownUI/Theme/TextStyle/TextStyle.swift b/Sources/MarkdownUI/Theme/TextStyle/TextStyle.swift index 29316dcb..acef762a 100644 --- a/Sources/MarkdownUI/Theme/TextStyle/TextStyle.swift +++ b/Sources/MarkdownUI/Theme/TextStyle/TextStyle.swift @@ -57,6 +57,6 @@ import SwiftUI /// ``` /// /// ![](CustomBlockquote) -public protocol TextStyle { +public protocol TextStyle : Sendable { func _collectAttributes(in attributes: inout AttributeContainer) } diff --git a/Sources/MarkdownUI/Utility/RelativeSize.swift b/Sources/MarkdownUI/Utility/RelativeSize.swift index 36ee9bfb..95626810 100644 --- a/Sources/MarkdownUI/Utility/RelativeSize.swift +++ b/Sources/MarkdownUI/Utility/RelativeSize.swift @@ -21,8 +21,8 @@ import SwiftUI /// FontSize(.em(2)) /// } /// ``` -public struct RelativeSize: Hashable { - enum Unit: Hashable { +public struct RelativeSize: Hashable, Sendable { + enum Unit: Hashable, Sendable { case em case rem }