Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Added singleton support so that no need to create property in application delegate. #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions Demo/DB5Demo/DB5AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,17 @@

@interface DB5AppDelegate ()

@property (nonatomic, strong) VSThemeLoader *themeLoader;
@property (nonatomic, strong) VSTheme *theme;
@end


@implementation DB5AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.themeLoader = [VSThemeLoader new];
self.theme = self.themeLoader.defaultTheme;
VSTheme *theme = [VSThemeLoader sharedInstance].defaultTheme;

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[DB5ViewController alloc] initWithNibName:@"DB5ViewController" bundle:nil theme:self.theme];
self.viewController = [[DB5ViewController alloc] initWithNibName:@"DB5ViewController" bundle:nil theme:theme];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

Expand Down
6 changes: 4 additions & 2 deletions Source/VSTheme.m
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,13 @@ static BOOL stringIsEmpty(NSString *s) {
NSString *redString = [s substringToIndex:2];
NSString *greenString = [s substringWithRange:NSMakeRange(2, 2)];
NSString *blueString = [s substringWithRange:NSMakeRange(4, 2)];
NSString *alphaString = [s substringWithRange:NSMakeRange(6, 2)];

unsigned int red = 0, green = 0, blue = 0;
unsigned int red = 0, green = 0, blue = 0, alpha = 0;
[[NSScanner scannerWithString:redString] scanHexInt:&red];
[[NSScanner scannerWithString:greenString] scanHexInt:&green];
[[NSScanner scannerWithString:blueString] scanHexInt:&blue];
[[NSScanner scannerWithString:alphaString] scanHexInt:&alpha];

return [UIColor colorWithRed:(CGFloat)red/255.0f green:(CGFloat)green/255.0f blue:(CGFloat)blue/255.0f alpha:1.0f];
return [UIColor colorWithRed:(CGFloat)red/255.0f green:(CGFloat)green/255.0f blue:(CGFloat)blue/255.0f alpha:(CGFloat)alpha/255.0f];
}
1 change: 1 addition & 0 deletions Source/VSThemeLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@property (nonatomic, strong, readonly) VSTheme *defaultTheme;
@property (nonatomic, strong, readonly) NSArray *themes;

+ (VSThemeLoader*)sharedInstance;
- (VSTheme *)themeNamed:(NSString *)themeName;

@end
9 changes: 9 additions & 0 deletions Source/VSThemeLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@ @interface VSThemeLoader ()
@end


static VSThemeLoader *singletonManager = nil;

@implementation VSThemeLoader

+ (VSThemeLoader*)sharedInstance{

if(singletonManager == nil)
singletonManager = [[super allocWithZone:NULL] init];

return singletonManager;
}

- (id)init {

Expand Down