From 4109e2a34cd3bb8db6692f13dc563fb36cdbdee1 Mon Sep 17 00:00:00 2001 From: Hwee-Boon Yar Date: Tue, 22 Apr 2014 21:41:37 +0800 Subject: [PATCH] Support using a custom path for plist --- Source/VSThemeLoader.h | 2 ++ Source/VSThemeLoader.m | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Source/VSThemeLoader.h b/Source/VSThemeLoader.h index 4c2d2be..d50a13b 100644 --- a/Source/VSThemeLoader.h +++ b/Source/VSThemeLoader.h @@ -16,6 +16,8 @@ @property (nonatomic, strong, readonly) VSTheme *defaultTheme; @property (nonatomic, strong, readonly) NSArray *themes; ++ (id)newWithContentsOfFile:(NSString *)path; ++ (NSString*)defaultFilePath; - (VSTheme *)themeNamed:(NSString *)themeName; @end diff --git a/Source/VSThemeLoader.m b/Source/VSThemeLoader.m index bbbe4c6..d2d8dcb 100644 --- a/Source/VSThemeLoader.m +++ b/Source/VSThemeLoader.m @@ -20,14 +20,31 @@ @interface VSThemeLoader () @implementation VSThemeLoader ++ (id)newWithContentsOfFile:(NSString *)path { + + return [[self alloc] initWithContentsOfFile:path]; +} + + ++ (NSString*)defaultFilePath { + + return [[NSBundle mainBundle] pathForResource:@"DB5" ofType:@"plist"]; +} + + - (id)init { + return [self initWithContentsOfFile:[[self class] defaultFilePath]]; +} + + +- (id)initWithContentsOfFile:(NSString *)path { + self = [super init]; if (self == nil) return nil; - NSString *themesFilePath = [[NSBundle mainBundle] pathForResource:@"DB5" ofType:@"plist"]; - NSDictionary *themesDictionary = [NSDictionary dictionaryWithContentsOfFile:themesFilePath]; + NSDictionary *themesDictionary = [NSDictionary dictionaryWithContentsOfFile:path]; NSMutableArray *themes = [NSMutableArray array]; for (NSString *oneKey in themesDictionary) {