diff --git a/TodoList/TodoList.xcodeproj/project.pbxproj b/TodoList/TodoList.xcodeproj/project.pbxproj index 17baea5..f3729b6 100644 --- a/TodoList/TodoList.xcodeproj/project.pbxproj +++ b/TodoList/TodoList.xcodeproj/project.pbxproj @@ -7,6 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + 29DC02311B44D98300C3F5B7 /* Item.m in Sources */ = {isa = PBXBuildFile; fileRef = 29DC022C1B44D98300C3F5B7 /* Item.m */; }; + 29DC02321B44D98300C3F5B7 /* List.m in Sources */ = {isa = PBXBuildFile; fileRef = 29DC022E1B44D98300C3F5B7 /* List.m */; }; + 29DC02331B44D98300C3F5B7 /* ListManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 29DC02301B44D98300C3F5B7 /* ListManager.m */; }; 8D9789F71B3C9A7F007CF4CF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D9789F61B3C9A7F007CF4CF /* main.m */; }; /* End PBXBuildFile section */ @@ -23,6 +26,12 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 29DC022B1B44D98300C3F5B7 /* Item.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Item.h; sourceTree = ""; }; + 29DC022C1B44D98300C3F5B7 /* Item.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Item.m; sourceTree = ""; }; + 29DC022D1B44D98300C3F5B7 /* List.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = List.h; sourceTree = ""; }; + 29DC022E1B44D98300C3F5B7 /* List.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = List.m; sourceTree = ""; }; + 29DC022F1B44D98300C3F5B7 /* ListManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ListManager.h; sourceTree = ""; }; + 29DC02301B44D98300C3F5B7 /* ListManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ListManager.m; sourceTree = ""; }; 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 = ""; }; /* End PBXFileReference section */ @@ -58,6 +67,12 @@ isa = PBXGroup; children = ( 8D9789F61B3C9A7F007CF4CF /* main.m */, + 29DC022B1B44D98300C3F5B7 /* Item.h */, + 29DC022C1B44D98300C3F5B7 /* Item.m */, + 29DC022D1B44D98300C3F5B7 /* List.h */, + 29DC022E1B44D98300C3F5B7 /* List.m */, + 29DC022F1B44D98300C3F5B7 /* ListManager.h */, + 29DC02301B44D98300C3F5B7 /* ListManager.m */, ); path = TodoList; sourceTree = ""; @@ -118,7 +133,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 29DC02321B44D98300C3F5B7 /* List.m in Sources */, + 29DC02311B44D98300C3F5B7 /* Item.m in Sources */, 8D9789F71B3C9A7F007CF4CF /* main.m in Sources */, + 29DC02331B44D98300C3F5B7 /* ListManager.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..9cbdc8b --- /dev/null +++ b/TodoList/TodoList/Item.h @@ -0,0 +1,27 @@ +// +// Item.h +// toDoListFromScratchZoufAndAyuna +// +// Created by Ayuna Vogel on 6/30/15. +// Copyright (c) 2015 Ayuna Vogel. All rights reserved. +// + +#import +#import "Item.h" +#import "List.h" +#import "ListManager.h" + +@class ListManager; +@class List; +@class Item; + +@interface Item : NSObject +-(void) setItem: (NSString *) item; +-(void) addItemDescription; +-(void) setItemPriority: (int) itemPriority; +-(NSString*) itemName; +-(int) itemPriority; +-(BOOL) markedDone; +-(void) setMarkedDone:(BOOL)markedDone; + +@end diff --git a/TodoList/TodoList/Item.m b/TodoList/TodoList/Item.m new file mode 100644 index 0000000..5508dfa --- /dev/null +++ b/TodoList/TodoList/Item.m @@ -0,0 +1,51 @@ +// +// Item.m +// toDoListFromScratchZoufAndAyuna +// +// Created by Ayuna Vogel on 6/30/15. +// Copyright (c) 2015 Ayuna Vogel. All rights reserved. +// + +#import "Item.h" + +@implementation Item { + + NSString* _itemName; + int _itemPriority; + BOOL _markedDone; +} + +-(void) setItem: (NSString *) item { + _itemName = item; +} + +-(void) addItemDescription { + NSLog(@"Enter task description: "); + //fgets method allows user to input more than one word ie: "finish project" + char itemInput[256]; + fgets(itemInput, 256, stdin); + NSString *itemDescription = [NSString stringWithUTF8String:itemInput]; + //stringWithUTF8String converts char to string + [self setItem: itemDescription]; +} + +-(NSString*) itemName { + return _itemName; +} + +-(void) setItemPriority: (int) itemPriority { + _itemPriority = itemPriority; +} + +-(int) itemPriority { + return _itemPriority; +} +-(void) setMarkedDone:(BOOL)markedDone { + _markedDone = markedDone; +} + +-(BOOL) markedDone { + return _markedDone; +} + +@end diff --git a/TodoList/TodoList/List.h b/TodoList/TodoList/List.h new file mode 100644 index 0000000..6e574ae --- /dev/null +++ b/TodoList/TodoList/List.h @@ -0,0 +1,30 @@ +// +// List.h +// toDoListFromScratchZoufAndAyuna +// +// Created by Ayuna Vogel on 6/30/15. +// Copyright (c) 2015 Ayuna Vogel. All rights reserved. +// + +#import +#import "Item.h" +#import "List.h" +#import "ListManager.h" + +@class ListManager; +@class List; +@class Item; + +@interface List : NSObject +-(void)setListName: (NSString *) listName; +-(NSString *) listName; +-(NSMutableArray *) itemsInList; +-(void) addItemToList: (Item *) task; +-(void) deleteItemFromList; +-(void) printAllItemsInList; +-(void) markItemDone: (Item *) task; +-(void) renameItem; +-(void) listOptions; +-(void) goBackToLists; +-(void) addListDescription; +@end \ No newline at end of file diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m new file mode 100644 index 0000000..bc50115 --- /dev/null +++ b/TodoList/TodoList/List.m @@ -0,0 +1,171 @@ +// +// List.m +// toDoListFromScratchZoufAndAyuna +// +// Created by Ayuna Vogel on 6/30/15. +// Copyright (c) 2015 Ayuna Vogel. All rights reserved. +// + +#import "List.h" +@class ListManager; +@class List; + +@implementation List { + NSString* _listName; + NSMutableArray* _itemsInList; +} + +-(void)setListName:(NSString *)listName { + _listName = listName; +} +-(NSString*) listName { + return _listName; +} +-(NSMutableArray*)itemsInList { + if (_itemsInList == nil) { + _itemsInList = [[NSMutableArray alloc] init]; + } + return _itemsInList; +} + +-(void) addItemToList: (Item*) task { + [_itemsInList addObject:task]; +} +-(void) deleteItemFromList { + NSLog(@"Enter a number to delete task"); + int j; + scanf("%d", &j); + [_itemsInList removeObjectAtIndex:j-1]; +} + +-(void) printAllItemsInList { + for (int i = 0; i < [_itemsInList count]; i++) { + NSString *itemName = [[_itemsInList objectAtIndex:i] itemName]; + int itemPriority = [[_itemsInList objectAtIndex:i] itemPriority]; + NSLog(@"%i) %@, priority %d", i+1, itemName, itemPriority); + } +} + +-(void) printAllCompletedItems:(BOOL) value { + for (int i = 0; i < [_itemsInList count]; i++) { + if ([[_itemsInList objectAtIndex:i] markedDone] == value) { + NSString *itemName = [[_itemsInList objectAtIndex:i] itemName]; + int itemPriority = [[_itemsInList objectAtIndex:i] itemPriority]; + NSLog(@"%i %@, priority %d", i+1, itemName, itemPriority); + } + } +} + +-(void) markItemDone: (Item *) task { + NSLog(@"Enter a number to mark task done"); + int j; + scanf("%d", &j); + for (int i = 0; i < [_itemsInList count]; i++) { + if (i == j) { + NSString *task = [[_itemsInList objectAtIndex:j-1] itemName]; + NSString *printTaskAsCompleted = [NSString stringWithFormat:@"✔︎ %i %@", i, task]; + [[_itemsInList objectAtIndex:j-1] setMarkedDone:YES]; + NSLog(@"%@", printTaskAsCompleted); + } + } +} + +-(void) renameItem { + [self printAllItemsInList]; + NSLog(@"Enter a number to edit task"); + int j; + scanf("%d", &j); + fpurge(stdin); + NSLog(@"Enter new task description"); + char newTaskName[256]; + fgets(newTaskName, 256, stdin); + NSString *editedTaskName = [NSString stringWithUTF8String:newTaskName]; + [[_itemsInList objectAtIndex:j-1] setItem:editedTaskName]; +} + +-(void) goBackToLists { + //if (_lists == nil) { + //allocate new object of ListManager + // } + //[[_lists objectAtIndex: i] listManagerMenuOptions]; + // int j; +// scanf("%d", &j); +// for (int i = 0; i < [_lists count]; i++) { +// if (j == 8) { +// [[_lists objectAtIndex:i] listManagerMenuOptions]; +// } +// } +} + +-(void) addListDescription { + NSLog(@"Enter list description: "); + char listDescriptionInput[256]; + fgets(listDescriptionInput, 256, stdin); + NSString *listDescription = [NSString stringWithUTF8String:listDescriptionInput]; + //stringWithUTF8String converts char to string + [self setListName:listDescription]; +} + +-(void) listOptions { + int i; + BOOL runListOptionsMenu = true; + while (runListOptionsMenu) { + + NSArray *listOptions = [[NSArray alloc] initWithObjects:@"1 - Display all tasks", @"2 - Add new task", @"3 - Edit task", @"4 - Delete task", @"5 - Mark task done", @"6 - List all active tasks", @"7 - List completed tasks", @"8 - Go back to Lists Menu", @"0 - Quit", nil]; + + NSLog(@"%@", listOptions); + scanf("%d", &i); + fpurge(stdin); + + if (i == 1) { + //display all items in the selected list + [self printAllItemsInList]; + } + else if (i == 2) { + //add new item + Item *newToDoItem = [[Item alloc]init]; + [newToDoItem addItemDescription]; + [newToDoItem itemName]; + [self addItemToList:newToDoItem]; + } + else if (i == 3) { + //rename item + [self renameItem]; + } + else if (i == 4) { + //delete item + [self printAllItemsInList]; + [self deleteItemFromList]; + NSLog(@"Deleted"); + } + else if (i == 5) { + //mark task done + [self printAllItemsInList]; + NSLog(@"Enter a task number to mark it completed"); + int i; + scanf("%d", &i); + //[self markItemDone]; + } + else if (i == 6) { + [self printAllCompletedItems:NO]; + } + else if (i == 7) { + //print all items in list, versions: either excluding marked done items, or print all incl marked done items with a check sign + [self printAllItemsInList]; + } + else if (i == 8) { + [self goBackToLists]; + } + else if (i == 0) { + NSLog(@"It was good to see you! Bye!"); + break; + } + else { + NSLog(@"Bummer! Try again?"); + } + } +} + + +@end + diff --git a/TodoList/TodoList/ListManager.h b/TodoList/TodoList/ListManager.h new file mode 100644 index 0000000..cd52268 --- /dev/null +++ b/TodoList/TodoList/ListManager.h @@ -0,0 +1,25 @@ +// +// ListManager.h +// toDoListFromScratchZoufAndAyuna +// +// Created by Ayuna Vogel on 6/30/15. +// Copyright (c) 2015 Ayuna Vogel. All rights reserved. +// + +#import +#import "Item.h" +#import "List.h" +#import "ListManager.h" + +@class ListManager; +@class List; +@class Item; + +@interface ListManager : NSObject +-(NSMutableArray*) getLists; +-(void) addListToListManager: (List*) list; +-(void) renameList; +-(void) deleteListFromListManager; +-(void) printLists; +-(void) listManagerMenuOptions; +@end \ No newline at end of file diff --git a/TodoList/TodoList/ListManager.m b/TodoList/TodoList/ListManager.m new file mode 100644 index 0000000..7b831eb --- /dev/null +++ b/TodoList/TodoList/ListManager.m @@ -0,0 +1,104 @@ +// +// ListManager.m +// toDoListFromScratchZoufAndAyuna +// +// Created by Ayuna Vogel on 6/30/15. +// Copyright (c) 2015 Ayuna Vogel. All rights reserved. +// + +#import "ListManager.h" + +@class Item; +@class List; + +@implementation ListManager { + NSMutableArray *_lists; +} +- (NSMutableArray *) getLists { + if (_lists == nil) { + _lists = [[NSMutableArray alloc] init]; + } + return _lists; +} + +-(void) addListToListManager: (List*) list { + [_lists addObject:list]; +} + +-(void) renameList { + [self printLists]; + int j; + scanf("%d", &j); + fpurge(stdin); + NSLog(@"Enter new list description"); + char newUserListName[256]; + fgets(newUserListName, 256, stdin); + NSString *editedListName = [NSString stringWithUTF8String:newUserListName]; + [[_lists objectAtIndex:j-1] setListName:editedListName]; +} + +-(void) deleteListFromListManager { + int j; + scanf("%d", &j); + [_lists removeObjectAtIndex:j-1]; +} + +-(void)printLists { + for (int i = 0; i < [_lists count]; i++) { + NSString *listName = [[_lists objectAtIndex:i] listName]; + NSLog(@"%i) %@", i+1, listName); + } + NSLog(@"Enter a number to pick a list"); +} + +-(void) listManagerMenuOptions { + int userInputInteger; + BOOL runListManagerMenuOptions = true; + while (runListManagerMenuOptions) { + + NSArray *listManagerMenuOptions = [[NSArray alloc] initWithObjects:@"1 - Display all to-do lists", @"2 - Add new to-do list", @"3 - Rename a to-do list", @"4 - Delete a to-do list", @"0 - Quit", @"Enter a number to pick your option:", nil]; + NSLog(@"%@", listManagerMenuOptions); + scanf("%d", &userInputInteger); + fpurge(stdin); + + if (userInputInteger == 1) { + [self printLists]; + int j; + scanf("%d", &j); + for (int i = 0; i < [_lists count]; i++) { + if (i == j -1 ) { + [[_lists objectAtIndex:i] listOptions]; + } + } + + break; + } + else if (userInputInteger == 2) { + List *newToDoList = [[List alloc]init]; + [newToDoList addListDescription]; + [newToDoList itemsInList]; + [newToDoList listName]; + [self addListToListManager:newToDoList]; + } + else if (userInputInteger == 3) { + //rename a list + [self renameList]; + } + else if (userInputInteger == 4) { + // delete a to-do list + [self printLists]; + [self deleteListFromListManager]; + NSLog(@"Deleted"); + } + else if (userInputInteger == 0) { + NSLog(@"It was good to see you! Bye!"); + break; + } + else { + NSLog(@"Bummer! Try again?"); + } + } +} + +@end + diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 187be40..6e57025 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -1,17 +1,78 @@ // // main.m -// TodoList +// toDoListFromScratchZoufAndAyuna // -// Created by Michael Kavouras on 6/25/15. -// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// Created by Ayuna Vogel on 6/28/15. +// Copyright (c) 2015 Ayuna Vogel. All rights reserved. // #import +#import "Item.h" +#import "List.h" +#import "ListManager.h" + +@class ListManager; +@class List; +@class Item; + +// ************ *********** ****** >>> MAIN FUNCTION <<< ********* ******** ********** int main(int argc, const char * argv[]) { @autoreleasepool { - // insert code here... - NSLog(@"Hello, World!"); + Item *firstTask = [[Item alloc]init]; + [firstTask setItem:@"Buy bananas"]; + [firstTask setItemPriority:1]; + + Item *secondTask = [[Item alloc]init]; + [secondTask setItem:@"Buy coffee and tea"]; + [secondTask setItemPriority:2]; + + List *groceryList = [[List alloc]init]; + [groceryList setListName:@"Grocery List"]; + [groceryList itemsInList]; + [groceryList addItemToList:firstTask]; + [groceryList addItemToList:secondTask]; + //[groceryList printAllItemsInList]; + //[groceryList editItemName:secondTask]; + + + Item *finishToDoListAppProject = [[Item alloc] init]; + [finishToDoListAppProject setItem:@"Finish to-do list app project"]; + [finishToDoListAppProject setItemPriority:1]; + + Item *learnGitBranching = [[Item alloc] init]; + [learnGitBranching setItem:@"Learn Git branching"]; + [learnGitBranching setItemPriority:2]; + + Item *readBook = [[Item alloc] init]; + [readBook setItem:@"Read Objective-C programming: The big nerd ranch guide book"]; + [readBook setItemPriority:3]; + + List *homeworkToDoList = [[List alloc] init]; + [homeworkToDoList itemsInList]; + [homeworkToDoList setListName:@"Homework"]; + [homeworkToDoList addItemToList:finishToDoListAppProject]; + [homeworkToDoList addItemToList:learnGitBranching]; + [homeworkToDoList addItemToList:readBook]; + //[homeworkToDoList printAllItemsInList]; + + ListManager *allLists = [[ListManager alloc]init]; + [allLists getLists]; + [allLists addListToListManager: groceryList]; + [allLists addListToListManager:homeworkToDoList]; + + //[groceryList deleteItemFromList:firstTask]; + //[groceryList printAllItemsInList]; + //[groceryList markItemDone:secondTask]; + //[groceryList printAllItemsInList]; + //[groceryList listOptions]; + + + NSLog(@"Welcome to your to-do list app! Let's get you started:\n"); + [allLists listManagerMenuOptions]; //prints List Manager options menu + + + } return 0; }