Adding my two-cents here!
I have this simple property wrapper:
/// A property wrapper that allows access to a Sample File.
/// Before the file is accessed, it's first copied into it's on mutable copy so we don't affect any other tests.
@propertyWrapper
public struct SampleFile: Sendable {
private let fileName: String
init(fileName: String) {
self.fileName = fileName
}
public var wrappedValue: Data {
let file = fileName.split(separator: ".").first!
let fileExtension = fileName.split(separator: ".").last!
let url = Bundle.module.url(forResource: String(file), withExtension: String(fileExtension))!
return try! Data(contentsOf: url)
}
}
- It's nonmutating
- It's Sendable
Yet, it's not working with Strict Concurrency enabled.
- nonisolated(unsafe) does not work with Property Wrappers
- The compiler is still not smart enough to do:
getonly ornonmutating setproperty wrappers would have their backing storage defined with alet.
That would solve this and sounds like a reasonable way forward.
But how about Macros?
Well, yes, that would solve it. Honestly, I can very easily rewrite the above example as well. However, Macros are more complicated to create compared to property wrappers and if this is the way forward, I feel like we should consider property wrappers to be deprecated or such since I don't see a way now to make them work with Strict Concurrency.
I'd love to get some more thoughts on this and the current state.
@Douglas_Gregor what is your vision on Property Wrappers and Strict Concurrency?