Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modernization + add TRACE_CALL variadic function to better illustrate object creation / life-cycle. #9

Open
wants to merge 1 commit 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
47 changes: 33 additions & 14 deletions Examples/AutoTodoList/AutoTodoList.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -45,6 +46,8 @@
28D7ACF70DDB3853001CB0EB /* TodoListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TodoListViewController.m; sourceTree = "<group>"; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
32CA4F630368D1EE00C91783 /* AutoTodoList_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AutoTodoList_Prefix.pch; sourceTree = "<group>"; };
7B58E9BB17FD3D5200679898 /* HRCoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HRCoder.h; path = ../HRTodoList/HRCoder/HRCoder.h; sourceTree = "<group>"; };
7B58E9BC17FD3D5200679898 /* HRCoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HRCoder.m; path = ../HRTodoList/HRCoder/HRCoder.m; sourceTree = "<group>"; };
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 = "<group>"; };
B25BC0F9146AA0FB00008FB3 /* BaseModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseModel.h; sourceTree = "<group>"; };
B25BC0FA146AA0FB00008FB3 /* BaseModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BaseModel.m; sourceTree = "<group>"; };
Expand All @@ -71,23 +74,23 @@
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 = "<group>";
};
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 = "<group>";
Expand Down Expand Up @@ -121,6 +124,8 @@
29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
isa = PBXGroup;
children = (
7B58E9BB17FD3D5200679898 /* HRCoder.h */,
7B58E9BC17FD3D5200679898 /* HRCoder.m */,
01F9DECE162B743900877219 /* AutoCoding */,
B25BC0F8146AA0FB00008FB3 /* BaseModel */,
080E96DDFE201D6D7F000001 /* Classes */,
Expand Down Expand Up @@ -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;
Expand All @@ -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 */,
);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
};
Expand Down
17 changes: 15 additions & 2 deletions Examples/AutoTodoList/AutoTodoList_Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
#define OBJC_OLD_DISPATCH_PROTOTYPES 0

#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <objc/runtime.h>

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
1 change: 0 additions & 1 deletion Examples/AutoTodoList/Classes/NewItemViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Copyright 2010 Charcoal Design. All rights reserved.
//

#import <UIKit/UIKit.h>

@class TodoItem;

Expand Down
34 changes: 8 additions & 26 deletions Examples/AutoTodoList/Classes/NewItemViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down
6 changes: 3 additions & 3 deletions Examples/AutoTodoList/Classes/TodoItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 7 additions & 15 deletions Examples/AutoTodoList/Classes/TodoItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Examples/AutoTodoList/Classes/TodoList.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@

@interface TodoList : BaseModel

@property (nonatomic, strong) NSMutableArray *items;
@property NSMutableArray *items;

@end
20 changes: 9 additions & 11 deletions Examples/AutoTodoList/Classes/TodoList.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 2 additions & 5 deletions Examples/AutoTodoList/Classes/TodoListAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
// Copyright Charcoal Design 2010. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface TodoListAppDelegate : NSObject <UIApplicationDelegate>

@property (nonatomic, strong) IBOutlet UIWindow *window;
@property (nonatomic, strong) IBOutlet UIViewController *viewController;
@property (nonatomic) IBOutlet UIWindow *window;
@property IBOutlet UIViewController *viewController;

@end

10 changes: 2 additions & 8 deletions Examples/AutoTodoList/Classes/TodoListAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions Examples/AutoTodoList/Classes/TodoListViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
// Copyright Charcoal Design 2010. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface TodoListViewController : UITableViewController

- (IBAction)createNewItem;
- (IBAction) createNewItem;

@end

Loading