diff --git a/TodoList/TodoList.xcodeproj/project.pbxproj b/TodoList/TodoList.xcodeproj/project.pbxproj index 17baea5..8a9a73b 100644 --- a/TodoList/TodoList.xcodeproj/project.pbxproj +++ b/TodoList/TodoList.xcodeproj/project.pbxproj @@ -7,6 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + 00824B7A1B4208690025BB5F /* Item.m in Sources */ = {isa = PBXBuildFile; fileRef = 00824B791B4208690025BB5F /* Item.m */; }; + 00824B7C1B42093C0025BB5F /* List.m in Sources */ = {isa = PBXBuildFile; fileRef = 00824B7B1B42093C0025BB5F /* List.m */; }; + 00824B7E1B4209E80025BB5F /* Manager.m in Sources */ = {isa = PBXBuildFile; fileRef = 00824B7D1B4209E80025BB5F /* Manager.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 */ + 00824B791B4208690025BB5F /* Item.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Item.m; sourceTree = ""; }; + 00824B7B1B42093C0025BB5F /* List.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = List.m; sourceTree = ""; }; + 00824B7D1B4209E80025BB5F /* Manager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Manager.m; sourceTree = ""; }; + 00824B801B420FEC0025BB5F /* Item.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Item.h; sourceTree = ""; }; + 00824B811B4210410025BB5F /* List.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = List.h; sourceTree = ""; }; + 00824B821B42108A0025BB5F /* Manager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Manager.h; 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 */, + 00824B821B42108A0025BB5F /* Manager.h */, + 00824B7D1B4209E80025BB5F /* Manager.m */, + 00824B801B420FEC0025BB5F /* Item.h */, + 00824B791B4208690025BB5F /* Item.m */, + 00824B811B4210410025BB5F /* List.h */, + 00824B7B1B42093C0025BB5F /* List.m */, ); path = TodoList; sourceTree = ""; @@ -118,7 +133,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 00824B7C1B42093C0025BB5F /* List.m in Sources */, + 00824B7A1B4208690025BB5F /* Item.m in Sources */, 8D9789F71B3C9A7F007CF4CF /* main.m in Sources */, + 00824B7E1B4209E80025BB5F /* 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..4ea6854 --- /dev/null +++ b/TodoList/TodoList/Item.h @@ -0,0 +1,19 @@ +// +// Item.h +// TodoList +// +// Created by Felicia Weathers on 6/29/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#ifndef TodoList_Item_h +#define TodoList_Item_h + +@interface Item: NSObject + +@property (nonatomic) NSString *content; + +@end + + +#endif diff --git a/TodoList/TodoList/Item.m b/TodoList/TodoList/Item.m new file mode 100644 index 0000000..5ddc54e --- /dev/null +++ b/TodoList/TodoList/Item.m @@ -0,0 +1,19 @@ +// +// Item.m +// TodoList +// +// Created by Felicia Weathers on 6/29/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import +#import "Item.h" + +@implementation Item + +-(NSString *)description +{ + return self.content; +} + +@end \ No newline at end of file diff --git a/TodoList/TodoList/List.h b/TodoList/TodoList/List.h new file mode 100644 index 0000000..fde8516 --- /dev/null +++ b/TodoList/TodoList/List.h @@ -0,0 +1,23 @@ +// +// List.h +// TodoList +// +// Created by Felicia Weathers on 6/29/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#ifndef TodoList_List_h +#define TodoList_List_h + +@interface List: NSObject + +@property (nonatomic) NSMutableArray *items; + +// Calls scanf and creates a new Item and adds that item to items array +-(Item *)scanItem; +-(NSMutableArray *)getItems; + +@end + + +#endif diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m new file mode 100644 index 0000000..f81b271 --- /dev/null +++ b/TodoList/TodoList/List.m @@ -0,0 +1,54 @@ +// +// List.m +// TodoList +// +// Created by Felicia Weathers on 6/29/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import +#import "Item.h" +#import "List.h" + +@implementation List + +-(NSString *)description +{ + // What gets printed when the object gets printed + return [NSString stringWithFormat:@"%@", self.items]; +} +-(Item *)scanItem +{ + if (!self.items) { + self.items = [[NSMutableArray alloc] init]; + } + + printf("What would you like to add to your list? (Or enter 0 to exit) \n"); + + + NSFileHandle *standardInput = [NSFileHandle fileHandleWithStandardInput]; + NSString *inputLine = [[[NSString alloc] initWithData:standardInput.availableData encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + + const char *command = [inputLine UTF8String]; + + if (command[0] == '0') { + + return nil; + } + + Item *item = [[Item alloc] init]; + item.content = (inputLine); + + [self.items addObject:item]; + + return item; +} + +-(NSMutableArray *)getItems +//@property (nonatomic) addComplete; + +{ + return self.items; +} + +@end diff --git a/TodoList/TodoList/Manager.h b/TodoList/TodoList/Manager.h new file mode 100644 index 0000000..d8298d0 --- /dev/null +++ b/TodoList/TodoList/Manager.h @@ -0,0 +1,20 @@ +// +// Manager.h +// TodoList +// +// Created by Felicia Weathers on 6/29/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#ifndef TodoList_Manager_h +#define TodoList_Manager_h +@interface Manager: NSObject + +@property (nonatomic) NSMutableArray *lists; + +- (void)start; + +@end + + +#endif diff --git a/TodoList/TodoList/Manager.m b/TodoList/TodoList/Manager.m new file mode 100644 index 0000000..17dc6a1 --- /dev/null +++ b/TodoList/TodoList/Manager.m @@ -0,0 +1,142 @@ +// +// Manager.m +// TodoList +// +// Created by Felicia Weathers on 6/29/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import +#import "Item.h" +#import "List.h" +#import "Manager.h" + + + + + + +@implementation Manager + +- (List *)createList +{ + if (!self.lists) { + self.lists = [[NSMutableArray alloc] init]; + } + + List *newList = [[List alloc] init]; + [self.lists addObject:newList]; + return newList; +} + + +-(int)showMenu +{ + printf("What would you like to do?\n0. Exit\n1. Create a list\n2. Print lists\n3. Remove content\n4. Edit Item\n"); + fpurge(stdin); + + int input; + scanf("%d", &input); + + return input; +} + +-(void)printLists +{ + // For each list in self.lists + for (List *list in self.lists) { + printf("%s\n", [[NSString stringWithFormat:@"%@", list] cStringUsingEncoding:NSUTF8StringEncoding]); + } +} + +-(void)start +{ + + while (true) { + int menuPicked = [self showMenu]; + + if (menuPicked == 0) { + break; + } + else if (menuPicked == 1){ + List *list = [self createList]; + while (true) { + Item *newItem = [list scanItem]; + if (!newItem) break; + } + } + else if (menuPicked == 2) { + [self printLists]; + } + else if (menuPicked == 3) { + printf("Which list would you like to access?\n"); + fpurge(stdin); + + int accessArray; + scanf("%d", &accessArray); + + printf("This list contains:\n"); + fpurge(stdin); + + [self printLists]; + + printf("What would you like to remove?\n"); + fpurge(stdin); + + + int deleteContent; + scanf("%d", &deleteContent); + + if ([[[self.lists objectAtIndex:accessArray-1]getItems] count] >= deleteContent) { + [[[self.lists objectAtIndex:accessArray-1]getItems]removeObjectAtIndex:deleteContent-1]; + fpurge(stdin); + } + else { + printf("Sorry that is not a valid option\n"); + fpurge(stdin); + } + } + /* else if (menuPicked == 4) { + printf("Which item would you like to mark as complete?\n"); + fpurge(stdin); + + [self printLists]; + + int markDone; + scanf("%d", &markDone); + + if ([[self.lists firstObject]getItems] count] >= markDone) { + [[self.lists firstObject]getItems] + } + + }*/ + else if (menuPicked == 4) { + printf("Which list would you like to access?\n"); + fpurge(stdin); + + int accessArray; + scanf("%d", &accessArray); + + printf("Which item would you like to edit?\n"); + fpurge(stdin); + + [self printLists]; + + int replaceItem; + scanf("%d", &replaceItem); + + if ([[[self.lists objectAtIndex:accessArray-1]getItems] count] >= replaceItem) { + + Item *newItem = [ [self.lists objectAtIndex:accessArray-1]scanItem]; + + if (newItem != nil) { + + [[[self.lists objectAtIndex:accessArray-1]getItems] replaceObjectAtIndex:replaceItem-1 withObject:newItem]; + + [[[self.lists objectAtIndex:accessArray-1]getItems] removeLastObject]; + } + } + } + } +} +@end diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 187be40..367d49f 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -8,10 +8,16 @@ #import +#import "Manager.h" + + + + int main(int argc, const char * argv[]) { @autoreleasepool { - // insert code here... - NSLog(@"Hello, World!"); + + Manager *manager = [[Manager alloc] init]; + [manager start]; } return 0; }