diff --git a/TodoList/TodoList.xcodeproj/project.pbxproj b/TodoList/TodoList.xcodeproj/project.pbxproj index 17baea5..7904682 100644 --- a/TodoList/TodoList.xcodeproj/project.pbxproj +++ b/TodoList/TodoList.xcodeproj/project.pbxproj @@ -8,6 +8,9 @@ /* Begin PBXBuildFile section */ 8D9789F71B3C9A7F007CF4CF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D9789F61B3C9A7F007CF4CF /* main.m */; }; + D4F83A8E1B425B8A005D40B4 /* Item.m in Sources */ = {isa = PBXBuildFile; fileRef = D4F83A8D1B425B8A005D40B4 /* Item.m */; }; + D4F83A911B425B98005D40B4 /* List.m in Sources */ = {isa = PBXBuildFile; fileRef = D4F83A901B425B98005D40B4 /* List.m */; }; + D4F83A941B425BA3005D40B4 /* Manager.m in Sources */ = {isa = PBXBuildFile; fileRef = D4F83A931B425BA3005D40B4 /* Manager.m */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -25,6 +28,12 @@ /* Begin PBXFileReference section */ 8D9789F31B3C9A7F007CF4CF /* TodoList */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = TodoList; sourceTree = BUILT_PRODUCTS_DIR; }; 8D9789F61B3C9A7F007CF4CF /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + D4F83A8C1B425B8A005D40B4 /* Item.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Item.h; sourceTree = ""; }; + D4F83A8D1B425B8A005D40B4 /* Item.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Item.m; sourceTree = ""; }; + D4F83A8F1B425B98005D40B4 /* List.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = List.h; sourceTree = ""; }; + D4F83A901B425B98005D40B4 /* List.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = List.m; sourceTree = ""; }; + D4F83A921B425BA3005D40B4 /* Manager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Manager.h; sourceTree = ""; }; + D4F83A931B425BA3005D40B4 /* Manager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Manager.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -58,6 +67,12 @@ isa = PBXGroup; children = ( 8D9789F61B3C9A7F007CF4CF /* main.m */, + D4F83A8C1B425B8A005D40B4 /* Item.h */, + D4F83A8D1B425B8A005D40B4 /* Item.m */, + D4F83A8F1B425B98005D40B4 /* List.h */, + D4F83A901B425B98005D40B4 /* List.m */, + D4F83A921B425BA3005D40B4 /* Manager.h */, + D4F83A931B425BA3005D40B4 /* Manager.m */, ); path = TodoList; sourceTree = ""; @@ -118,7 +133,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + D4F83A911B425B98005D40B4 /* List.m in Sources */, + D4F83A8E1B425B8A005D40B4 /* Item.m in Sources */, 8D9789F71B3C9A7F007CF4CF /* main.m in Sources */, + D4F83A941B425BA3005D40B4 /* Manager.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -235,6 +253,7 @@ 8D9789FC1B3C9A7F007CF4CF /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/TodoList/TodoList/Item.h b/TodoList/TodoList/Item.h new file mode 100644 index 0000000..a29dbc2 --- /dev/null +++ b/TodoList/TodoList/Item.h @@ -0,0 +1,19 @@ +// +// Item.h +// TodoList +// +// Created by Jason Wang on 6/30/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface Item : NSObject + +@property (nonatomic) NSString *content; +@property (nonatomic) int priority; +@property (nonatomic) BOOL done; + +- (instancetype)initWithContent:(NSString *)content priority:(int)priority ; + +@end diff --git a/TodoList/TodoList/Item.m b/TodoList/TodoList/Item.m new file mode 100644 index 0000000..a6e0c68 --- /dev/null +++ b/TodoList/TodoList/Item.m @@ -0,0 +1,34 @@ +// +// Item.m +// TodoList +// +// Created by Jason Wang on 6/30/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "Item.h" + +@implementation Item + +- (instancetype)initWithContent:(NSString *)content priority:(int)priority +{ + self = [super init]; + if (self) { + self.content = content; + self.priority = priority; + self.done = NO; + } + return self; +} + +-(NSString *)description +{ + if (self.done) { + return [NSString stringWithFormat:@"(Priority %@) [X] %@ ", @(self.priority), self.content]; + } else { + return [NSString stringWithFormat:@"(Priority %@) [ ] %@ ", @(self.priority), self.content]; + } + +} + +@end diff --git a/TodoList/TodoList/List.h b/TodoList/TodoList/List.h new file mode 100644 index 0000000..52787c7 --- /dev/null +++ b/TodoList/TodoList/List.h @@ -0,0 +1,21 @@ +// +// List.h +// TodoList +// +// Created by Jason Wang on 6/30/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import +#import "Item.h" + +@interface List : NSObject + +@property (nonatomic) NSMutableArray *items; +@property (nonatomic) NSString *title; +@property (nonatomic) int priority; + +-(void)showMenu; + + +@end diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m new file mode 100644 index 0000000..d5feb0e --- /dev/null +++ b/TodoList/TodoList/List.m @@ -0,0 +1,142 @@ +// +// List.m +// TodoList +// +// Created by Jason Wang on 6/30/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "List.h" +#import "Manager.h" + +@implementation List + +- (instancetype)init +{ + self = [super init]; + if (self) { + self.items = [[NSMutableArray alloc] init]; + } + return self; +} + +-(int)getPriority { + [Manager printString:@"Enter priority (1 - 4):"]; + int priority = [Manager getInputString].intValue; + if (priority < 1 || priority > 4) { + [Manager printString:@"Outside limits! 1 is min, 4 is max."]; + //instead of making the worlds saddest loop; recursion +// while (priority < 1 || priority > 4) { +// [Manager printString:@"Enter priority (1 - 4):"]; +// priority = [Manager getInputString].intValue; +// } + return [self getPriority]; + } + return priority; +} + +-(Item *)addItem { + [Manager printString:@"Enter task:"]; + NSString *task = [Manager getInputString]; + + int priority = [self getPriority]; + + Item *newItem = [[Item alloc] initWithContent:task priority:priority]; + [self.items addObject:newItem]; + + [self printList]; + return newItem; + +} + +-(void)removeItem { + [self printList]; + [Manager printString:@"Choose the index to remove:"]; + int removeIndex = [Manager getInputString].intValue-1; + [self.items removeObjectAtIndex:removeIndex]; + [self printList]; +} + +-(void)editItem { + [self printList]; + [Manager printString:@"Choose the index to edit:"]; + int editIndex = [Manager getInputString].intValue-1; + Item *item = [self.items objectAtIndex:editIndex]; + + [Manager printString:@"Enter task:"]; + NSString *task = [Manager getInputString]; + + int priority = [self getPriority]; + + item.content = task; + item.priority = priority; + [self printList]; + +} + +-(void)markDone { + [self printList]; + [Manager printString:@"Chose the index to Mark Done:"]; + int markIndex = [Manager getInputString].intValue-1; + Item *markItem = [self.items objectAtIndex:markIndex]; + markItem.done = YES; +} + +-(void)printList { + [Manager printString:[NSString stringWithFormat:@"Title: %@", self.title]]; + [Manager printString:self.description]; +} + + +-(NSString *)description +{ + NSMutableString *desc = [[NSMutableString alloc] init]; + [desc appendString:@"\n"]; + for (int i = 0; i < self.items.count; i++) { + NSString *newLine = [NSString stringWithFormat:@"%@: %@\n",@(i+1), self.items[i]]; + [desc appendString:newLine]; + } + return desc; +} + + +-(void)printMenu { + [Manager printString:[NSString stringWithFormat:@"\n\n~[%@]~\n \nChoose form the following:", self.title]]; + [Manager printString:@"1. Print list"]; + [Manager printString:@"2. Add Item"]; + [Manager printString:@"3. Remove Item"]; + [Manager printString:@"4. Edit Item"]; + [Manager printString:@"5. Mark Done"]; + [Manager printString:@"99. Main menu"]; +} + +-(int)getMenuInput { + [self printMenu]; + return [Manager getInputString].intValue; +} + +-(void)showMenu { + while (true) { + int input = [self getMenuInput]; + if (input == 1) { + [self printList]; + } + else if (input == 2) { + [self addItem]; + } + else if (input == 3) { + [self removeItem]; + } + else if (input == 4) { + [self editItem]; + } + else if (input == 5) { + [self markDone]; + } + else if (input == 99) { + break; + } + } +} + +@end diff --git a/TodoList/TodoList/Manager.h b/TodoList/TodoList/Manager.h new file mode 100644 index 0000000..a2aa375 --- /dev/null +++ b/TodoList/TodoList/Manager.h @@ -0,0 +1,20 @@ +// +// Manager.h +// TodoList +// +// Created by Jason Wang on 6/30/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface Manager : NSObject + +@property (nonatomic) NSMutableArray *lists; + ++(NSString *)getInputString; ++(void)printString:(NSString *)string; + +-(void)showMenu; + +@end diff --git a/TodoList/TodoList/Manager.m b/TodoList/TodoList/Manager.m new file mode 100644 index 0000000..da64e8e --- /dev/null +++ b/TodoList/TodoList/Manager.m @@ -0,0 +1,87 @@ +// +// Manager.m +// TodoList +// +// Created by Jason Wang on 6/30/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "Manager.h" +#import "List.h" + +@implementation Manager + +- (instancetype)init +{ + self = [super init]; + if (self) { + self.lists = [[NSMutableArray alloc] init]; + } + return self; +} + +// Gets the input from scanf as an NSString ++(NSString *)getInputString { + int numLength = 1024; + char input[numLength]; + fgets(input, numLength, stdin); + fflush(stdin); + + // Gets rid of \n at the end of each input + size_t length = strlen(input) - 1; + if (input[length] == '\n') + input[length] = '\0'; + + return [NSString stringWithUTF8String:input]; +} + ++(void)printString:(NSString *)string { + printf("%s\n", [string cStringUsingEncoding:NSUTF8StringEncoding]); +} + +-(List *)createList { + List *newList = [[List alloc] init]; + [Manager printString:@"List name:"]; + newList.title = [Manager getInputString]; + [self.lists addObject:newList]; + return newList; + +} + +-(void)printMenu { + [Manager printString:@"Main menu. Choose form the following:"]; + [Manager printString:@"1. Print all lists"]; + [Manager printString:@"2. Create List"]; + [Manager printString:@"99. Exit"]; +} + +-(int)getMenuInput { + [self printMenu]; + return [Manager getInputString].intValue; +} + +-(void)printLists { + for (List *list in self.lists) { + [Manager printString:list.title]; + [Manager printString:list.description]; + } +} + +-(void)showMenu { + while (true) { + int input = [self getMenuInput]; + if (input == 1) { + [self printLists]; + } + else if (input == 2) { + List *newList = [self createList]; + [newList showMenu]; + } + else if (input == 99) { + break; + } + } +} + + +@end diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 187be40..171147f 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -1,17 +1,18 @@ // // main.m -// TodoList +// Natalias_ToDo // -// Created by Michael Kavouras on 6/25/15. -// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// Created by Natalia Estrella on 6/28/15. +// Copyright (c) 2015 Natalia Estrella. All rights reserved. // #import +#import "Manager.h" int main(int argc, const char * argv[]) { @autoreleasepool { - // insert code here... - NSLog(@"Hello, World!"); + Manager *manager = [[Manager alloc] init]; + [manager showMenu]; } return 0; }