Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Marin Usalj committed Dec 7, 2012
1 parent 70e8be9 commit dc4777c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 32 deletions.
43 changes: 22 additions & 21 deletions Demo/NUIDemo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,36 @@

#import "AppDelegate.h"

@implementation AppDelegate {
NSMutableArray *demoItems;
}
@implementation AppDelegate

@synthesize window = _window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[NUIAppearance loadStylesheet:@"Blue.NUIStyle"];
[NUIAppearance initializeWithStylesheet:@"Blue.NUIStyle"];

NSArray *demoItems = @[
@{
@"name" : @"John",
@"description" : @"Guitar"
},
@{
@"name" : @"Paul",
@"description" : @"Bass"
},
@{
@"name" : @"George",
@"description" : @"Guitar"
},
@{
@"name" : @"Ringo",
@"description" : @"Drums"
}
];

demoItems = [NSMutableArray arrayWithCapacity:20];
[demoItems addObject:[NSDictionary dictionaryWithObjectsAndKeys:
@"John", @"name",
@"Guitar", @"description",
nil]];
[demoItems addObject:[NSDictionary dictionaryWithObjectsAndKeys:
@"Paul", @"name",
@"Bass", @"description",
nil]];
[demoItems addObject:[NSDictionary dictionaryWithObjectsAndKeys:
@"George", @"name",
@"Guitar", @"description",
nil]];
[demoItems addObject:[NSDictionary dictionaryWithObjectsAndKeys:
@"Ringo", @"name",
@"Drums", @"description",
nil]];
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController = [[tabBarController viewControllers] objectAtIndex:1];

NUIDemoTableViewController *demoTableViewController = [[navigationController viewControllers] objectAtIndex:0];
demoTableViewController.demoItems = demoItems;

Expand Down
2 changes: 1 addition & 1 deletion Demo/NUIDemo/NUIDemoTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

@interface NUIDemoTableViewController : UITableViewController

@property (nonatomic, strong) NSMutableArray *demoItems;
@property (nonatomic, strong) NSArray *demoItems;

@end
2 changes: 1 addition & 1 deletion NUI/Core/NUIAppearance.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

@interface NUIAppearance : NSObject

+ (void)loadStylesheet:(NSString *)stylesheet;
+ (void)initializeWithStylesheet:(NSString *)stylesheet;

@end
4 changes: 2 additions & 2 deletions NUI/Core/NUIAppearance.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

@implementation NUIAppearance

+ (void)loadStylesheet:(NSString *)stylesheet
+ (void)initializeWithStylesheet:(NSString *)stylesheet
{
[NUISettings loadStylesheet:stylesheet];

[self initUINavigationBar];
[self initUIBarButtonItem];
}
Expand Down
2 changes: 1 addition & 1 deletion NUI/Core/NUIConverter.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ + (float)toFloat:(id)value

+ (NSNumber*)toNumber:(id)value
{
return [NSNumber numberWithFloat:[value floatValue]];
return @([value floatValue]);
}

+ (CGSize)toSize:(NSString*)value
Expand Down
4 changes: 4 additions & 0 deletions NUI/Core/NUISettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

@interface NUISettings : NSObject

#pragma mark - Initialization
+ (void)loadStylesheet:(NSString*)name;
+ (NUISettings*)instance;

#pragma mark - Public
+ (BOOL)hasProperty:(NSString*)property withClass:(NSString*)class_name;
+ (id)get:(NSString*)property withClass:(NSString*)class_name;
+ (BOOL)getBoolean:(NSString*)property withClass:(NSString*)class_name;
Expand Down
16 changes: 10 additions & 6 deletions NUI/Core/NUISettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@
#import "NUISettings.h"

@interface NUISettings ()
@property(nonatomic,retain) NSDictionary *settings;
@property(nonatomic,retain) NSDictionary *stylesheet;
@end

@implementation NUISettings

static NUISettings *singleton = nil;
static NUISettings *singleton;


+ (void)loadStylesheet:(NSString *)name
{
self.instance.settings = [[NUIStyleParser new] getStylesFromFile:name];
self.instance.stylesheet = [[NUIStyleParser new] getStylesFromFile:name];
}

+ (BOOL)hasProperty:(NSString*)property withExplicitClass:(NSString*)class_name
{
NSDictionary *ruleSet = self.instance.settings[class_name];
NSDictionary *ruleSet = self.instance.stylesheet[class_name];
if (ruleSet == nil || ruleSet[property] == nil) {
return NO;
}
Expand All @@ -43,7 +44,7 @@ + (BOOL)hasProperty:(NSString*)property withClass:(NSString*)class_name

+ (id)get:(NSString*)property withExplicitClass:(NSString*)class_name
{
NSDictionary *ruleSet = self.instance.settings[class_name];
NSDictionary *ruleSet = self.instance.stylesheet[class_name];
return ruleSet[property];
}

Expand Down Expand Up @@ -109,11 +110,14 @@ + (NSArray*)getClasses:(NSString*)class_name
return classes;
}


#pragma mark - Private

+ (NUISettings*)instance
{
static dispatch_once_t singletonToken;
dispatch_once(&singletonToken, ^{
singleton = [[self alloc] init];
singleton = [NUISettings new];
});

return singleton;
Expand Down

0 comments on commit dc4777c

Please sign in to comment.