๐ฐKey Path
Keypaths allow you to refer to properties without invoking them โ you hold a reference to the property itself, rather than reading its value.
Key paths ไธป่ฆไธ็จฎ่ฎ้ซ(้ๆๅ ถไป)
KeyPath: read-only access to a property.
WritableKeyPath: readwrite access to a mutable property with value semantics (so the instance in question also needs to be mutable for writes to be allowed).
ReferenceWritableKeyPath: can only be used with reference types, and provides readwrite access to any mutable property.
Keypaths in Swift have a few more types, which mostly revolve around type-erasure, like with Any. When you combine or allow multiple keypaths, for example in an array, you can use the PartialKeyPath and AnyKeyPath to construct types that fit multiple keypaths.
Examples
๐ replit
Last updated