jspahrsummers / libextobjc

A Cocoa library to extend the Objective-C programming language.
MIT License
4.53k stars 462 forks source link

Problem in EXTAspect with NSManagedObjects from CoreData #38

Open Antol opened 11 years ago

Antol commented 11 years ago

In CoreData entity (child of NSManagedObject) work little bit tricky. Doc says:

NSManagedObject uses dynamic class generation to support the Objective-C 2 
properties feature (see “Objective-C 2 Support”) by automatically creating a subclass of 
your class appropriate for your entity. This is also typically transparent to you, however 
whereas NSManagedObject’s class method returns your class, the Objective-C 
function object_getClass returns the dynamically-generated class.

This leads to the fact that in

- (void)adviseSetters:(void (^)(void))body property:(NSString *)property

property == nil

Antol commented 11 years ago

One way to fix it is replace object_getClass(self) with [self class] in

static void setterAdviceMethod (ffi_cif *cif, void *result, void **args, void *userdata)

But I'm not sure about it

jspahrsummers commented 10 years ago

Unfortunately, EXTAspect is not really supported code. It was mostly a proof-of-concept, and I really wouldn't recommend using it in production.