Search code examples
objective-ccore-datamustachetemplate-engineobjective-c-category

GRMustache core data category not visible?


I've a bunch of core data models 'NSManagedObject subclasses' with a couple of categories for each. I want the template to use attributes from model's category, which is from what I understand is ok since:

[model valueForKey:@"attributeName"];

is actually returning the desired value!

BUT when I evaluate it in a mustache template it returns an empty string!!

so this code snippet is returning an empty string:

NSString *template = @"{{# experiences }}{{experienceElement}}{{/ experiences }}";
return [GRMustacheTemplate renderObject:self fromString:template error:nil];

where self is another model's category that has experiences as an attribute (NSSet) and experienceElement is a function that returns a string in Experience Model's category.

but it works when I replace experienceElement with a real attribute in the Experience model it self!

what is wrong on this implementation?

note: this is a cocoa mac app, using libGRMustache7-MacOS.a


Solution

  • Starting from v 7.0.0 for the sake of security

    A new safe key access constraint was introduced to limit keys to only class properties

    A solution is to declare a read only property at the category with the name of the method

    at category_file.h

    @property (nonatomic, readonly) NSString * experienceElement
    

    at category_file.m

    -(NSString*) experienceElement
    {
        NSString *newValue = @"";//derive new value
        return newValue; 
    }