From 320e3065d251e11370e571df5705675937b76521 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Thu, 28 Feb 2013 21:42:23 +0100 Subject: [PATCH 1/1] Better constructor for Config. --- Config.h | 1 + Config.m | 18 +++++++----------- ConfigsController.m | 9 +++------ 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/Config.h b/Config.h index 2572669..cc96f2a 100644 --- a/Config.h +++ b/Config.h @@ -14,6 +14,7 @@ @property (copy) NSString *name; @property (readonly) NSMutableDictionary *entries; +- (id)initWithName:(NSString *)name; - (Target *)objectForKeyedSubscript:(JSAction *)action; - (void)setObject:(Target *)target forKeyedSubscript:(JSAction *)action; diff --git a/Config.m b/Config.m index 84e6c32..5a83ed3 100644 --- a/Config.m +++ b/Config.m @@ -9,30 +9,26 @@ #import "JSAction.h" -@implementation Config { - NSMutableDictionary *entries; -} - -@synthesize name; -@synthesize entries; +@implementation Config -- (id)init { +- (id)initWithName:(NSString *)name { if ((self = [super init])) { - entries = [[NSMutableDictionary alloc] init]; + self.name = name; + _entries = [[NSMutableDictionary alloc] init]; } return self; } - (Target *)objectForKeyedSubscript:(JSAction *)action { - return action ? entries[action.uid] : nil; + return action ? _entries[action.uid] : nil; } - (void)setObject:(Target *)target forKeyedSubscript:(JSAction *)action { if (action) { if (target) - entries[action.uid] = target; + _entries[action.uid] = target; else - [entries removeObjectForKey:action.uid]; + [_entries removeObjectForKey:action.uid]; } } diff --git a/ConfigsController.m b/ConfigsController.m index dbb2c6f..4227d43 100644 --- a/ConfigsController.m +++ b/ConfigsController.m @@ -24,8 +24,7 @@ - (id)init { if ((self = [super init])) { configs = [[NSMutableArray alloc] init]; - currentConfig = [[Config alloc] init]; - currentConfig.name = @"(default)"; + currentConfig = [[Config alloc] initWithName:@"(default)"]; manualConfig = currentConfig; [configs addObject:currentConfig]; } @@ -60,8 +59,7 @@ } - (IBAction)addPressed:(id)sender { - Config *newConfig = [[Config alloc] init]; - newConfig.name = @"untitled"; + Config *newConfig = [[Config alloc] initWithName:@"Untitled"]; [configs addObject:newConfig]; [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged]; [tableView reloadData]; @@ -139,8 +137,7 @@ // have to do two passes in case config1 refers to config2 via a TargetConfig for (NSDictionary *storedConfig in storedConfigs) { - Config *cfg = [[Config alloc] init]; - cfg.name = storedConfig[@"name"]; + Config *cfg = [[Config alloc] initWithName:storedConfig[@"name"]]; [newConfigs addObject:cfg]; } -- 2.20.1