Skip to content

Instantly share code, notes, and snippets.

@NikolaiRuhe
Created September 23, 2022 11:53
Show Gist options
  • Save NikolaiRuhe/456eb626d494fc26a3e9077b7fe5fee9 to your computer and use it in GitHub Desktop.
Save NikolaiRuhe/456eb626d494fc26a3e9077b7fe5fee9 to your computer and use it in GitHub Desktop.
extension Binding where Value: MutableCollection, Value.Element: Identifiable {
subscript(_ id: Value.Element.ID) -> Binding<Value.Element> {
let index = wrappedValue.firstIndex { $0.id == id }
guard let index else {
fatalError("id not found: \(id)")
}
return self[index]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment