Created
December 12, 2013 09:36
-
-
Save nicholascross/7925422 to your computer and use it in GitHub Desktop.
Cache BMGlyphFont instead of recreating it everytime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <BMGlyphLabel/BMGlyphFont.h> | |
@interface BMGlyphFont (MMCache) | |
+ (BMGlyphFont *) cachedFontWithName:(NSString *)name; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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