A Swift dictionary type that conforms to Sendable
protocol for Swift 6.
The Any
type does not conform to Sendable
and therefore Dictionaries of [String: Any]
are not Sendable
.
SendableDict
is a wrapper around [String: Any]
that conforms to Sendable
.
The conversion supports most primitive Swift types and nested Arrays/Dictionaries.
let dict: [String:Any] = [
"key1": 1,
"key2": "Hello",
"key3": true,
"key4": ["nestedKey": 2.0]
]
let sendableDict: SendableDict = dict.sendable()
// or
let sendableDict: SendableDict = SendableDict(dict: dict)
// Note: Any value that was not Sendable will be lost.
let anotherDict: [String: Any] = sendableDict.dict