-
v1.11.0 deprecated one of the dynamic member lookup subscripts in favor of the failable struct Tree: Identifiable, Sendable {
var id: UUID = .init()
var nodes: [Tree] = []
subscript(path pathIds: [Tree.ID]) -> Tree? {
get { … }
set { … }
}
}
let tree = Shared(Tree())
let node = tree[path: […]]
// 👆'subscript(dynamicMember:)' is deprecated: Use 'Shared($value.optional)' to unwrap optional shared values It's possible to use the other dynamic lookup subscript by explicitly giving the type: let tree = Shared(Tree())
let node: Shared<Tree?> = tree[path: […]]
let optional = Shared(node) I use this pattern quite a few times in my app so I'd like to avoid this two-step dance. I suppose I could create an extension that bypasses the dynamic member lookup altogether: extension Shared where Value == Tree {
subscript(path pathIds: [Tree.ID]) -> Shared<Tree>? {
let node: Shared<Tree?> = self[path: pathIds]
return Shared(node)
}
} Of course, this means I need to do this for each type and subscript. Is there a more general, ergonomic solution that I'm missing? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @seanmrich, this will be fixed with #3170, which we will merge and release in 1.12 soon. |
Beta Was this translation helpful? Give feedback.
Hi @seanmrich, this will be fixed with #3170, which we will merge and release in 1.12 soon.