Skip to content

Instantly share code, notes, and snippets.

@nicholascross
Created December 12, 2013 09:36
Show Gist options
  • Save nicholascross/7925422 to your computer and use it in GitHub Desktop.
Save nicholascross/7925422 to your computer and use it in GitHub Desktop.
Cache BMGlyphFont instead of recreating it everytime
#import <Foundation/Foundation.h>
#import <BMGlyphLabel/BMGlyphFont.h>
@interface BMGlyphFont (MMCache)
+ (BMGlyphFont *) cachedFontWithName:(NSString *)name;
@end
#import "BMGlyphFont+MMCache.h"
@implementation BMGlyphFont (MMCache)
+ (BMGlyphFont *)cachedFontWithName:(NSString *)name {
id font = [[self fontCache] valueForKey:name];
if (!font) {
font = [BMGlyphFont fontWithName:name];
[[self fontCache] setObject:font forKey:name];
}
return font;
}
+ (NSMutableDictionary *)fontCache {
static NSMutableDictionary *fontCache;
static dispatch_once_t pred;
dispatch_once(&pred, ^{
fontCache = [[NSMutableDictionary alloc] init];
});
return fontCache;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment