Skip to content

SwiftfulThinking/SendableDictionary

Repository files navigation

Swift Wormhold SendableDict

SendableDict 🛸

A Swift dictionary type that conforms to Sendable protocol for Swift 6.

About

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.

Implementation

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]
]

Convert to Sendable

let sendableDict: SendableDict = dict.sendable()
// or
let sendableDict: SendableDict = SendableDict(dict: dict)

Convert back

// Note: Any value that was not Sendable will be lost.
let anotherDict: [String: Any] = sendableDict.dict

About

Sendable dictionary type for Swift 6

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages