Closed jonathandann closed 8 years ago
That's very interesting, thank you @jonathandann! Let's dive into this session :smile:
Inspired by this WWDC session, the following code snippets actually do successfully execute NSObject's implementation of valueForKey:
on NSArray, NSSet and NSOrderedSet (this trick helps us evaluating tags like {{ items.count }}
):
// Using class_getMethodImplementation
typedef id (*send_type)(id, SEL, id);
send_type func = (send_type)class_getMethodImplementation([NSObject class], @selector(valueForKey:));
return func(object, @selector(valueForKey:), key);
// Using objc_msgSendSuper
typedef id (*send_type)(struct objc_super *, SEL, id key);
send_type func = (send_type)objc_msgSendSuper;
return func(&(struct objc_super){ .receiver = object, .super_class = [NSObject class] }, @selector(valueForKey:), key);
I still have to test them on arm64, and pick my favorite option :-)
This would be a nice fix to issue #70, much better than the current one (https://github.com/groue/GRMustache/blob/master/src/classes/Rendering/GRMustacheKeyAccess.m#L204-L337)
This issue will become obsolete with #100.
+[GRMustacheKeyAccess valueForMustacheKey:inFoundationCollectionObject:] does work if you cast the call to objc_msgSend() properly.
WWDC 2014, Session 417, "What's new in LLVM". "objc_msgSend without a typecast is usually an error."
ENABLE_STRICT_OBJC_MSGSEND can help