Inherits from NSObject
Declared in GRMustache.h

Overview

The GRMustache class provides with global-level information and configuration of the GRMustache library.

Tasks

Getting the GRMustache version

Preventing NSUndefinedKeyException in Development configuration

Standard Library

Building rendering objects

Class Methods

libraryVersion

The version of GRMustache as a GRMustacheVersion struct.

+ (GRMustacheVersion)libraryVersion

Return Value

The version of GRMustache as a GRMustacheVersion struct.

Availability

v7.0

Declared In

GRMustache.h

preventNSUndefinedKeyExceptionAttack

Have GRMustache avoid most NSUndefinedKeyExceptions when rendering templates.

+ (void)preventNSUndefinedKeyExceptionAttack

Availability

v1.7

Discussion

The rendering of a GRMustache template can lead to NSUndefinedKeyExceptions to be raised, because of the usage of the valueForKey: method. Those exceptions are nicely handled by GRMustache, and are part of the regular rendering of a template.

Unfortunately, Objective-C exceptions have several drawbacks, particularly:

  1. they play badly with autorelease pools, and are reputed to leak memory.
  2. they usually stop your debugger when you are developping your application.

The first point is indeed a matter of worry: Apple does not guarantee that exceptions raised by valueForKey: do not leak memory. However, I never had any evidence of such a leak from NSObject’s implementation.

Should you still worry, we recommend that you avoid the valueForKey: method altogether. Instead, implement the keyed subscripting objectForKeyedSubscript: method on objects that you provide to GRMustache.

The second point is valid also: NSUndefinedKeyException raised by template rendering may become a real annoyance when you are debugging your project, because it’s likely you’ve told your debugger to stop on every Objective-C exceptions.

You can avoid them as well: make sure you invoke once, early in your application, the preventNSUndefinedKeyExceptionAttack method.

Depending on the number of NSUndefinedKeyException that get prevented, you will experience a slight performance hit, or a performance improvement.

Since the main use case for this method is to avoid Xcode breaks on rendering exceptions, the best practice is to conditionally invoke this method, using the NS_BLOCK_ASSERTIONS#documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html) that helps identifying the Debug configuration of your targets:

#if !defined(NS_BLOCK_ASSERTIONS)
// Debug configuration: keep GRMustache quiet
[GRMustache preventNSUndefinedKeyExceptionAttack];
#endif

Companion guide: https://github.com/groue/GRMustache/blob/master/Guides/runtime.md

Declared In

GRMustache.h

renderingObjectForObject:

This method is deprecated. Use [GRMustacheRendering renderingObjectForObject:] instead. (Deprecated: v7.0)

+ (id<GRMustacheRendering>)renderingObjectForObject:(id)object

Availability

v6.0

See Also

Declared In

GRMustache.h

renderingObjectWithBlock:

This method is deprecated. Use [GRMustacheRendering renderingObjectWithBlock:] instead. (Deprecated: v7.0)

+ (id<GRMustacheRendering>)renderingObjectWithBlock:(NSString *( ^ ) ( GRMustacheTag *tag , GRMustacheContext *context , BOOL *HTMLSafe , NSError **error ))block

Availability

v6.0

See Also

Declared In

GRMustache.h

standardLibrary

The GRMustache standard library.

+ (NSObject *)standardLibrary

Return Value

The GRMustache standard library.

Companion guide: https://github.com/groue/GRMustache/blob/master/Guides/standard_library.md

Availability

v6.4

Declared In

GRMustache.h