I don't understand "#keyPath()"

In Chapter 2, there are two uses of what appears to be a function called “#keyPath

NSPredicate(format: "%K = %@", argumentArray: [#keyPath(BowTie.searchKey), ... ])

these are the only instances of the string “keyPath” that I can find in the project, and searching through both Swift and Apple documentation I can’t figure out what it means to have a “#” before a function name.

What’s going on here?

@pavedwalden You use #keyPath() to create key paths that are checked at compile time instead of using raw strings which may crash at runtime. This improves both key value coding and observing mechanisms used by Core Data under the hood.

You can read even more about how this works over here:

Please let me know if you have any other questions or more issues about the whole thing when you get a chance. Thank you!

1 Like

Thanks so much, this answers my questions about #keyPath()

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.