miku1958
(Miku1958)
1
The AttributedString is Sendable, but AttributedString.paragraphStyle is NSParagraphStyle, which is not Sendable, so this code in Swift 5.9 will give me this error:
var attributeString = AttributedString("")
attributeString.paragraphStyle = NSParagraphStyle() // Conformance of 'NSParagraphStyle' to 'Sendable' is unavailable
I raise a feedback since Xcode 15 b1, but it still happen in b6, it seems Apple doesn't care about this, so is there any solution to disable Sendable check to a setter?
1 Like
jflan
(John Flanagan)
2
I would love a proper solution, but this works as an awkward workaround that doesn't produce a warning:
var attributeString = AttributedString("")
attributeString.mergeAttributes(.init([.paragraphStyle: style]))
Jon_Shier
(Jon Shier)
3
You can use extension NSParagraphStyle: @unchecked Sendable {} in your code. Technically it may be unsafe due to NSParagraph style being a class with a mutable subclass but as long as you don't mutate it directly it should be fine.
1 Like
jflan
(John Flanagan)
4
The warning in Xcode says that NSParagraphStyle has been explicitly marked as not Sendable. To you're point I'm assuming it's only because of the mutable subclass, but it still seems sketchy to retroactively conform a type to Sendable that has explicitly marked itself as not Sendable.
Although to be fair I'm sure my suggestion is also just skirting around an intended requirement of AttributedString.
Jon_Shier
(Jon Shier)
6
Oddly enough, Xcode 15b8 doesn't produce that warning, despite the fact that it's still explicitly unavailable in the module definition. It seems to be effective since the warning about NSParagraphStyle not being Sendable goes away. This seems like a bug.
1 Like
jqsilver
(Andy B)
7
I'm seeing this warning in Xcode 15.2 and 15.3. I created a new project and added this method to get a minimal repro:
func test() {
var container = AttributeContainer()
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineHeightMultiple = 0.5
container.paragraphStyle = paragraphStyle
}
On both versions I tested, I'm getting "Conformance of 'NSParagraphStyle' to 'Sendable' is unavailable"
jberry
(James Berry)
8
Try it like this instead:
let container = AttributeContainer([.paragraphStyle: paragraphStyle])
It may not be any more safe, but it eliminates the warning 
1 Like
jqsilver
(Andy B)
9
Thank you! I was having a hard time figuring out the solution just from reading the AttributeContainer documentation.