Introduction to Swift Keypaths

Erase Types

released Fri, 29 Mar 2019
Swift Version 5.0

1. Erase Types

We already saw this, but it is worth mentioning again. One reason why keypaths are so useful is because there're type-erased variants. As we saw in our practical example, the ability to temporarily go to AnyKeyPath offers many more opportunities. So, always remember these types:

KeyPath<A, B> = \User.age
PartialKeyPath<A> = \User.age
AnyKeyPath = \User.age