From f9026773a9a2429bffacb1f964c2513ed39f66be Mon Sep 17 00:00:00 2001 From: Alex Gray Date: Fri, 4 Oct 2013 16:38:12 -0400 Subject: [PATCH] rebased to only include this commit amended --- .../AutoTodoList.xcodeproj/project.pbxproj | 47 ++++++--- Examples/AutoTodoList/AutoTodoList_Prefix.pch | 17 +++- .../Classes/NewItemViewController.h | 1 - .../Classes/NewItemViewController.m | 34 ++----- Examples/AutoTodoList/Classes/TodoItem.h | 6 +- Examples/AutoTodoList/Classes/TodoItem.m | 22 ++--- Examples/AutoTodoList/Classes/TodoList.h | 2 +- Examples/AutoTodoList/Classes/TodoList.m | 20 ++-- .../Classes/TodoListAppDelegate.h | 7 +- .../Classes/TodoListAppDelegate.m | 10 +- .../Classes/TodoListViewController.h | 3 +- .../Classes/TodoListViewController.m | 95 ++++++++----------- 12 files changed, 120 insertions(+), 144 deletions(-) diff --git a/Examples/AutoTodoList/AutoTodoList.xcodeproj/project.pbxproj b/Examples/AutoTodoList/AutoTodoList.xcodeproj/project.pbxproj index fcda30e..1d2a0ec 100755 --- a/Examples/AutoTodoList/AutoTodoList.xcodeproj/project.pbxproj +++ b/Examples/AutoTodoList/AutoTodoList.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ 2899E5220DE3E06400AC0155 /* TodoListViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2899E5210DE3E06400AC0155 /* TodoListViewController.xib */; }; 28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28AD733E0D9D9553002E5188 /* MainWindow.xib */; }; 28D7ACF80DDB3853001CB0EB /* TodoListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 28D7ACF70DDB3853001CB0EB /* TodoListViewController.m */; }; + 7B58E9BD17FD3D5200679898 /* HRCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B58E9BC17FD3D5200679898 /* HRCoder.m */; }; B25BC0FB146AA0FB00008FB3 /* BaseModel.m in Sources */ = {isa = PBXBuildFile; fileRef = B25BC0FA146AA0FB00008FB3 /* BaseModel.m */; }; B2CE7D5413E1729C00AB7DB4 /* TodoItem.m in Sources */ = {isa = PBXBuildFile; fileRef = B2CE7D5313E1729C00AB7DB4 /* TodoItem.m */; }; B2CE7D5713E172A700AB7DB4 /* TodoList.m in Sources */ = {isa = PBXBuildFile; fileRef = B2CE7D5513E172A700AB7DB4 /* TodoList.m */; }; @@ -45,6 +46,8 @@ 28D7ACF70DDB3853001CB0EB /* TodoListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TodoListViewController.m; sourceTree = ""; }; 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 32CA4F630368D1EE00C91783 /* AutoTodoList_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutoTodoList_Prefix.pch; sourceTree = ""; }; + 7B58E9BB17FD3D5200679898 /* HRCoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HRCoder.h; path = ../HRTodoList/HRCoder/HRCoder.h; sourceTree = ""; }; + 7B58E9BC17FD3D5200679898 /* HRCoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HRCoder.m; path = ../HRTodoList/HRCoder/HRCoder.m; sourceTree = ""; }; 8D1107310486CEB800E47090 /* AutoTodoList-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "AutoTodoList-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = ""; }; B25BC0F9146AA0FB00008FB3 /* BaseModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseModel.h; sourceTree = ""; }; B25BC0FA146AA0FB00008FB3 /* BaseModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BaseModel.m; sourceTree = ""; }; @@ -71,12 +74,12 @@ 01457AF311772690005BBF82 /* View Controllers */ = { isa = PBXGroup; children = ( + 01457AE8117723E2005BBF82 /* NewItemViewController.h */, + 01457AE9117723E2005BBF82 /* NewItemViewController.m */, 1D3623240D0F684500981E51 /* TodoListAppDelegate.h */, 1D3623250D0F684500981E51 /* TodoListAppDelegate.m */, 28D7ACF60DDB3853001CB0EB /* TodoListViewController.h */, 28D7ACF70DDB3853001CB0EB /* TodoListViewController.m */, - 01457AE8117723E2005BBF82 /* NewItemViewController.h */, - 01457AE9117723E2005BBF82 /* NewItemViewController.m */, ); name = "View Controllers"; sourceTree = ""; @@ -84,10 +87,10 @@ 01457AF41177269B005BBF82 /* Model */ = { isa = PBXGroup; children = ( - B2CE7D5613E172A700AB7DB4 /* TodoList.h */, - B2CE7D5513E172A700AB7DB4 /* TodoList.m */, B2CE7D5213E1729C00AB7DB4 /* TodoItem.h */, B2CE7D5313E1729C00AB7DB4 /* TodoItem.m */, + B2CE7D5613E172A700AB7DB4 /* TodoList.h */, + B2CE7D5513E172A700AB7DB4 /* TodoList.m */, ); name = Model; sourceTree = ""; @@ -121,6 +124,8 @@ 29B97314FDCFA39411CA2CEA /* CustomTemplate */ = { isa = PBXGroup; children = ( + 7B58E9BB17FD3D5200679898 /* HRCoder.h */, + 7B58E9BC17FD3D5200679898 /* HRCoder.m */, 01F9DECE162B743900877219 /* AutoCoding */, B25BC0F8146AA0FB00008FB3 /* BaseModel */, 080E96DDFE201D6D7F000001 /* Classes */, @@ -236,6 +241,22 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 7B7DF3F517FF3C85007F5BC4 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "#. ~/dotfiles/osx.sh\n#installonipad \"${CODESIGNING_FOLDER_PATH}\" | logger"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 1D60588E0D05DD3D006BFB54 /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -247,6 +268,7 @@ 01457AEB117723E2005BBF82 /* NewItemViewController.m in Sources */, B2CE7D5413E1729C00AB7DB4 /* TodoItem.m in Sources */, B2CE7D5713E172A700AB7DB4 /* TodoList.m in Sources */, + 7B58E9BD17FD3D5200679898 /* HRCoder.m in Sources */, B25BC0FB146AA0FB00008FB3 /* BaseModel.m in Sources */, 01F9DED1162B743900877219 /* AutoCoding.m in Sources */, ); @@ -277,6 +299,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ENABLE_OBJC_ARC = YES; + CODE_SIGN_IDENTITY = ""; COPY_PHASE_STRIP = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = AutoTodoList_Prefix.pch; @@ -289,35 +312,31 @@ C01FCF4F08A954540054247B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CLANG_ANALYZER_OBJC_UNUSED_IVARS = NO; GCC_C_LANGUAGE_STANDARD = c99; GCC_TREAT_WARNINGS_AS_ERRORS = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VALUE = NO; GCC_WARN_UNUSED_VARIABLE = YES; ONLY_ACTIVE_ARCH = YES; RUN_CLANG_STATIC_ANALYZER = YES; SDKROOT = iphoneos; - WARNING_CFLAGS = ( - "-Wall", - "-Wextra", - ); + WARNING_CFLAGS = ""; }; name = Debug; }; C01FCF5008A954540054247B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CLANG_ANALYZER_OBJC_UNUSED_IVARS = NO; GCC_C_LANGUAGE_STANDARD = c99; GCC_TREAT_WARNINGS_AS_ERRORS = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VALUE = NO; GCC_WARN_UNUSED_VARIABLE = YES; RUN_CLANG_STATIC_ANALYZER = YES; SDKROOT = iphoneos; - WARNING_CFLAGS = ( - "-Wall", - "-Wextra", - ); + WARNING_CFLAGS = ""; }; name = Release; }; diff --git a/Examples/AutoTodoList/AutoTodoList_Prefix.pch b/Examples/AutoTodoList/AutoTodoList_Prefix.pch index d764461..639a4d2 100644 --- a/Examples/AutoTodoList/AutoTodoList_Prefix.pch +++ b/Examples/AutoTodoList/AutoTodoList_Prefix.pch @@ -5,6 +5,19 @@ #define OBJC_OLD_DISPATCH_PROTOTYPES 0 #ifdef __OBJC__ - #import - #import + + #import + #import + #import + +NS_INLINE void TRACE_CALL(SEL _cmd_,id _obj_,...) { NSMutableString *mark; id obj = nil; va_list args; + + mark = [NSString stringWithFormat:@"%@[%@ %@", class_isMetaClass(object_getClass(_obj_)) ? @"+" : @"-", + NSStringFromClass([_obj_ class]), + NSStringFromSelector(_cmd_)].mutableCopy; + + va_start(args, _obj_); while ((obj = va_arg(args,id))) [mark appendFormat:@"%@",obj]; va_end(args); + printf("%s];\n",mark.UTF8String); +} + #endif diff --git a/Examples/AutoTodoList/Classes/NewItemViewController.h b/Examples/AutoTodoList/Classes/NewItemViewController.h index 0a0e5f0..00440eb 100644 --- a/Examples/AutoTodoList/Classes/NewItemViewController.h +++ b/Examples/AutoTodoList/Classes/NewItemViewController.h @@ -6,7 +6,6 @@ // Copyright 2010 Charcoal Design. All rights reserved. // -#import @class TodoItem; diff --git a/Examples/AutoTodoList/Classes/NewItemViewController.m b/Examples/AutoTodoList/Classes/NewItemViewController.m index f084dd5..dbd0ac3 100644 --- a/Examples/AutoTodoList/Classes/NewItemViewController.m +++ b/Examples/AutoTodoList/Classes/NewItemViewController.m @@ -10,37 +10,19 @@ #import "TodoList.h" #import "TodoItem.h" +@interface NewItemViewController() @property TodoItem *item; @end -@interface NewItemViewController() - -@property (nonatomic, strong) TodoItem *item; - -@end +@implementation NewItemViewController +#pragma mark - UITextViewDelegate methods -@implementation NewItemViewController +- (void)textViewDidChange:(UITextView *)tV { -@synthesize item; + // either update the existing TodoItem (setLabel:) + _item ? [_item setLabel:tV.text] // or create a new TodoItem and add to list (addObject:) + : [TodoList.sharedInstance.items addObject:_item = [TodoItem instanceWithLabel:tV.text]]; -#pragma mark - -#pragma mark UITextViewDelegate methods - -- (void)textViewDidChange:(UITextView *)textView -{ - if (item == nil) - { - //create a new TodoItem and add to list - self.item = [TodoItem instanceWithLabel:textView.text]; - [[TodoList sharedInstance].items addObject:item]; - } - else - { - //update the TodoItem - item.label = textView.text; - } - - //save the item - [item save]; + [_item save]; //save the item } #pragma mark - diff --git a/Examples/AutoTodoList/Classes/TodoItem.h b/Examples/AutoTodoList/Classes/TodoItem.h index d2b7d3b..68963b7 100644 --- a/Examples/AutoTodoList/Classes/TodoItem.h +++ b/Examples/AutoTodoList/Classes/TodoItem.h @@ -13,9 +13,9 @@ @interface TodoItem : BaseModel -@property (nonatomic, strong) NSString *label; -@property (nonatomic, assign) BOOL checked; +@property NSString * label; +@property BOOL checked; -+ (instancetype)instanceWithLabel:(NSString *)label; ++ (instancetype) instanceWithLabel:(NSString*)label; @end diff --git a/Examples/AutoTodoList/Classes/TodoItem.m b/Examples/AutoTodoList/Classes/TodoItem.m index e5801c8..81305c6 100644 --- a/Examples/AutoTodoList/Classes/TodoItem.m +++ b/Examples/AutoTodoList/Classes/TodoItem.m @@ -9,29 +9,21 @@ #import "TodoItem.h" #import "TodoList.h" - @implementation TodoItem -@synthesize label; -@synthesize checked; ++ (instancetype) instanceWithLabel:(NSString*)label { TRACE_CALL(_cmd, self, label, nil); -+ (instancetype)instanceWithLabel:(NSString *)label -{ - return [self instanceWithObject:label]; + return [self instanceWithObject:label]; } +- (void) setWithString: (NSString*)string { TRACE_CALL(_cmd, self, string, nil); -- (void)setWithString:(NSString *)string -{ - self.label = string; + _label = string; } +- (void) save { TRACE_CALL(_cmd, self, nil); -- (void)save -{ - //save the todolist - [[TodoList sharedInstance] save]; + [TodoList.sharedInstance save]; /*save the todolist*/ } -//note: we've not implemented the NSCoding methods -//the AutoCoding library takes care of this for us +//- (BOOL) useHRCoderIfAvailable { return YES; } note: we don't implement NSCoding methods as the AutoCoding library takes care of this by default. @end diff --git a/Examples/AutoTodoList/Classes/TodoList.h b/Examples/AutoTodoList/Classes/TodoList.h index 617e53e..da4c180 100644 --- a/Examples/AutoTodoList/Classes/TodoList.h +++ b/Examples/AutoTodoList/Classes/TodoList.h @@ -13,6 +13,6 @@ @interface TodoList : BaseModel -@property (nonatomic, strong) NSMutableArray *items; +@property NSMutableArray *items; @end diff --git a/Examples/AutoTodoList/Classes/TodoList.m b/Examples/AutoTodoList/Classes/TodoList.m index fcabb48..6aa646b 100644 --- a/Examples/AutoTodoList/Classes/TodoList.m +++ b/Examples/AutoTodoList/Classes/TodoList.m @@ -12,20 +12,18 @@ @implementation TodoList -@synthesize items; +- (void)setUp { TRACE_CALL(_cmd, self, nil); _items = NSMutableArray.new; } -- (void)setUp -{ - self.items = [NSMutableArray array]; -} +- (void)setWithArray:(NSArray*)array { TRACE_CALL(_cmd, self, array, nil); + + [self.items setArray:[TodoItem instancesWithArray:array]]; //initialise with default list from plist -- (void)setWithArray:(NSArray *)array -{ - //initialise with default list from plist - [items setArray:[TodoItem instancesWithArray:array]]; + printf("Just called +[TodoItem instancesWithArray:\n\t%s];\n" + "Note: initialise with default list from plist (%s)\nResource file:%s\nSave file:%s\n", + [[array valueForKey:@"description"] componentsJoinedByString:@"\n\t"].UTF8String, + NSStringFromSelector(_cmd).UTF8String, self.class.resourceFile.UTF8String, self.class.saveFile.UTF8String); } -//note: we've not implemented the NSCoding methods -//the AutoCoding library takes care of this for us +//- (BOOL) useHRCoderIfAvailable { return YES; } note: we don't implement NSCoding methods as the AutoCoding library takes care of this by default. @end diff --git a/Examples/AutoTodoList/Classes/TodoListAppDelegate.h b/Examples/AutoTodoList/Classes/TodoListAppDelegate.h index e478c62..34eecb3 100644 --- a/Examples/AutoTodoList/Classes/TodoListAppDelegate.h +++ b/Examples/AutoTodoList/Classes/TodoListAppDelegate.h @@ -6,13 +6,10 @@ // Copyright Charcoal Design 2010. All rights reserved. // -#import - - @interface TodoListAppDelegate : NSObject -@property (nonatomic, strong) IBOutlet UIWindow *window; -@property (nonatomic, strong) IBOutlet UIViewController *viewController; +@property (nonatomic) IBOutlet UIWindow *window; +@property IBOutlet UIViewController *viewController; @end diff --git a/Examples/AutoTodoList/Classes/TodoListAppDelegate.m b/Examples/AutoTodoList/Classes/TodoListAppDelegate.m index 401c61a..e7d3bb9 100644 --- a/Examples/AutoTodoList/Classes/TodoListAppDelegate.m +++ b/Examples/AutoTodoList/Classes/TodoListAppDelegate.m @@ -8,17 +8,11 @@ #import "TodoListAppDelegate.h" - @implementation TodoListAppDelegate -@synthesize window; -@synthesize viewController; +- (void)applicationDidFinishLaunching:(__unused UIApplication *)application { -- (void)applicationDidFinishLaunching:(__unused UIApplication *)application -{ - [window makeKeyAndVisible]; + [_window makeKeyAndVisible]; } - - @end diff --git a/Examples/AutoTodoList/Classes/TodoListViewController.h b/Examples/AutoTodoList/Classes/TodoListViewController.h index 0fbc25e..cf21be7 100644 --- a/Examples/AutoTodoList/Classes/TodoListViewController.h +++ b/Examples/AutoTodoList/Classes/TodoListViewController.h @@ -6,11 +6,10 @@ // Copyright Charcoal Design 2010. All rights reserved. // -#import @interface TodoListViewController : UITableViewController -- (IBAction)createNewItem; +- (IBAction) createNewItem; @end diff --git a/Examples/AutoTodoList/Classes/TodoListViewController.m b/Examples/AutoTodoList/Classes/TodoListViewController.m index 390cb4b..145513d 100644 --- a/Examples/AutoTodoList/Classes/TodoListViewController.m +++ b/Examples/AutoTodoList/Classes/TodoListViewController.m @@ -11,79 +11,62 @@ #import "TodoItem.h" #import "TodoList.h" - @implementation TodoListViewController -- (void)viewDidLoad -{ - [super viewDidLoad]; - self.navigationItem.leftBarButtonItem = self.editButtonItem; - self.clearsSelectionOnViewWillAppear = YES; -} +#pragma mark - UITableViewDataSource methods -- (void)viewWillAppear:(__unused BOOL)animated -{ - [super viewWillAppear:YES]; - [self.tableView reloadData]; -} +- (NSInteger) tableView:(UITableView*)tV numberOfRowsInSection:(NSInteger)sect { + + return TRACE_CALL(_cmd, self, @(TodoList.sharedInstance.items.count),nil), TodoList.sharedInstance.items.count; -- (IBAction)createNewItem -{ - UIViewController *viewController = [[NewItemViewController alloc] init]; - [self.navigationController pushViewController:viewController animated:YES]; } +- (UITableViewCell*) tableView:(UITableView*)tV cellForRowAtIndexPath:(NSIndexPath*)iPath { static NSString *cellType = @"Cell"; -#pragma mark - -#pragma mark UITableViewDelegate methods + TRACE_CALL(_cmd, self, @(iPath.row), nil); -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath -{ - TodoItem *item = [[TodoList sharedInstance].items objectAtIndex:indexPath.row]; - item.checked = !item.checked; - [item save]; + UITableViewCell *cell = [tV dequeueReusableCellWithIdentifier:cellType] + ?: [UITableViewCell.alloc initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellType]; - [tableView reloadData]; + TodoItem *item = TodoList.sharedInstance.items[iPath.row]; + cell.textLabel.text = item.label; + cell.accessoryType = item.checked ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone; + return cell; } -- (UITableViewCellEditingStyle)tableView:(__unused UITableView *)tableView editingStyleForRowAtIndexPath:(__unused NSIndexPath *)indexPath -{ - return UITableViewCellEditingStyleDelete; +#pragma mark - UITableViewDelegate methods + +- (void) tableView:(UITableView*)tV didSelectRowAtIndexPath:(NSIndexPath*)iPath { + + TRACE_CALL(_cmd, self, iPath, nil); + + TodoItem *item = TodoList.sharedInstance.items[iPath.row]; + item.checked = !item.checked; + + [item save]; [tV reloadData]; } +- (UITableViewCellEditingStyle) tableView:(UITableView*)tV editingStyleForRowAtIndexPath:(NSIndexPath*)iPath { -- (void)tableView:(UITableView *)tableView commitEditingStyle:(__unused UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath -{ - [[TodoList sharedInstance].items removeObjectAtIndex:indexPath.row]; - [[TodoList sharedInstance] save]; - - [tableView reloadData]; + return UITableViewCellEditingStyleDelete; } +- (void) tableView:(UITableView*)tV commitEditingStyle:(UITableViewCellEditingStyle)editStyle + forRowAtIndexPath:(NSIndexPath*)iPath { -#pragma mark - -#pragma mark UITableViewDataSource methods + TRACE_CALL(_cmd, self, nil); -- (NSInteger)tableView:(__unused UITableView *)table numberOfRowsInSection:(__unused NSInteger)section -{ - return [[TodoList sharedInstance].items count]; + [TodoList.sharedInstance.items removeObjectAtIndex:iPath.row]; + [TodoList.sharedInstance save]; + [tV reloadData]; } -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath -{ - static NSString *cellType = @"Cell"; - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellType]; - if (cell == nil) - { - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellType]; - } - - TodoItem *item = [[TodoList sharedInstance].items objectAtIndex:indexPath.row]; - cell.textLabel.text = item.label; - if (item.checked) { - cell.accessoryType = UITableViewCellAccessoryCheckmark; - } else { - cell.accessoryType = UITableViewCellAccessoryNone; - } - - return cell; +#pragma mark - Standard view methods + +- (void) viewDidLoad { [super viewDidLoad]; + + self.navigationItem.leftBarButtonItem = self.editButtonItem; + self.clearsSelectionOnViewWillAppear = YES; } +- (void) viewWillAppear:(BOOL)animated { [super viewWillAppear:YES]; [self.tableView reloadData]; } +- (IBAction) createNewItem { [self.navigationController pushViewController:NewItemViewController.new animated:YES]; } + @end