Daily iOS
Persistence

ObjC runtime model mapping

In the Objective-C days, YYModel and MJExtension turned JSON into models and even handled NSCoding archiving from nothing but the class definition. Which runtime feature made that possible?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Reflection in the ObjC runtime. class_copyPropertyList enumerates a class's properties at runtime to read their names and types, and KVC's setValue:forKey: injects the JSON values. Archiving walks the properties the same way to encode them, and the property metadata is cached once per class for performance.

Share a question