Access properties via subscripting in Swift

后端 未结 6 1586
情歌与酒
情歌与酒 2021-01-04 00:43

I have a custom class in Swift and I\'d like to use subscripting to access its properties, is this possible?

What I want is something like this:

clas         


        
6条回答
  •  被撕碎了的回忆
    2021-01-04 01:17

    (GRMustache author here)

    Until a swift-oriented Mustache library is out, I suggest having your classes inherit from NSObject (so that they have the valueForKey: method). GRMustache will then fetch values with this method.

    In case this would still not work (blank values in the rendering), you may try to disable GRMustache security features (see https://github.com/groue/GRMustache/blob/master/Guides/security.md#disabling-safe-key-access)

    Should you experience any other trouble, please open an issue right into the repository: https://github.com/groue/GRMustache/issues

    EDIT February 2, 2015: GRMustache.swift is out: http://github.com/groue/GRMustache.swift

提交回复
热议问题