Details
-
Type:
Improvement
-
Status: Open
-
Priority:
Medium
-
Resolution: Unresolved
-
Component/s: Foundation, Standard Library
-
Labels:None
-
Radar URL:
Description
Expose API to retrieve string representation of KeyPath
We can build a type-safe NSPredicate using KeyPath if we have such an API. We can use `_kvcKeyPathString` currently, but it would be nice if it will be officially visible as a public API.
For example, I created this experimental project using KeyPath and `_kvcKeyPathString`.
Using this extension, you can type-safely write queries that were previously hard-coded with strings as shown below. In addition to type checking, a typo can be prevented, and code completion works.
Before
NSPredicate(format: "name == %@", "Katsumi") NSPredicate(format: "age > %@", 20)
After
Query(Person.self).filter(\Person.name == "Katsumi")
Query(Person.self).filter(\Person.age > 20)
Query(Person.self).filter(\Person.name > 20) // Compile error Query(Person.self).filter(\Dog.name == "John") // Compile error
Attachments
Issue Links
- is duplicated by
-
SR-6270 Accessing _kvcKeyPathString
-
- Resolved
-