Chapter 1 KVC explanation seems mistaken

In Chapter 1, pg. 29 there is the following code:

 cell.textLabel?.text =
  person.value(forKeyPath: "name") as? String

With the accompanying blurb:

Why do you have to do this? As it turns out, NSManagedObject doesn’t know about the name attribute you defined in your Data Model, so there’s no way of accessing it directly with a property. The only way Core Data provides to read the value is key- value coding, commonly referred to as KVC.

Perhaps this intended to expose the reader to KVC since its used in many places in core data apparently but why not this code instead:

cell.textLabel?.text =

It seems infinitely better since it’s not stringly typed and much clearer IMHO. Is there something wrong in doing it this way or this just a missed update of the changes in iOS 10?

Thanks so much,


@jaolmos Thanks very much for your question! The solution you provide is indeed correct, however, the KVC solution is initially provided to the reader before introducing the subject of ManagedObjectSubclasses. The approach you’re using involves the use of ManagedObjectSubclasses and the KVC approach is used so that the reader can appreciate the approach you show when the chapter of ManagedObjectSubclasses is discussed. Once the ManagedObjectSubclass chapter is introduced, the KVC approach is no longer used going forward :slight_smile: I hope this makes sense!

All the best!