【问题标题】:GRMustache core data category not visible?GRMustache 核心数据类别不可见?
【发布时间】:2014-12-17 13:15:53
【问题描述】:

我有一堆核心数据模型“NSManagedObject 子类”,每个模型都有几个类别。 我希望模板使用模型类别中的属性,据我了解,这是可以的,因为:

[model valueForKey:@"attributeName"];

实际上是返回所需的值!

但是当我在 mustache 模板中评估它时,它返回一个空字符串!!

所以这段代码 sn-p 返回一个空字符串:

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

其中 self 是另一个模型的类别,将体验作为属性 (NSSet),而 experienceElement 是返回体验模型类别中的字符串的函数。

但是当我将 ExperienceElement 替换为 Experience 模型中的真实属性时它会起作用!

这个实现有什么问题?

注意:这是一个 cocoa mac 应用,使用 libGRMustache7-MacOS.a

【问题讨论】:

    标签: objective-c core-data mustache template-engine objective-c-category


    【解决方案1】:

    为了security从v 7.0.0开始

    引入了新的safe key access 约束以将键限制为仅类属性

    一种解决方案是在类别中声明一个只读属性,并带有方法的名称

    在 category_file.h

    @property (nonatomic, readonly) NSString * experienceElement
    

    在 category_file.m

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

    【讨论】:

    • 是的,我只是没有注意到关键的安全内容。感谢您的快速回复和伟大的 GRMustache。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多