You can achieve your approach by following method:
unsigned int count;
objc_property_t *properties = class_copyPropertyList([CoreDataObject class], &count);
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithCapacity:16];
for(int i = 0; i < count; i++) {
objc_property_t property = properties[i];
NSString *name = [NSString stringWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
id obj = [coreDataObjectInstance valueForKey:name];
if (obj) {
// Skip properties with nil values (optionally you can use: [dictionary setObject:((obj == nil) ? [NSNull null] : obj) forKey:name]; without any if-statement)
[dictionary setObject:obj forKey:name];
}
}
free(properties);
"CoreDataObject" is the core data object you would like to convert into a NSDictionary while "coreDataObjectInstance" is an instance of this core data object.
Keep in mind you have to:
#include <objc/runtime.h>
Furthermore, it would be great if you can give us some more insights what you would like to achieve with this idea, maybe there is a different/better solution.
Hope this helps!