From b72236f5804a364a596c29d74a5f188dd304f897 Mon Sep 17 00:00:00 2001 From: Natalia Estrella Date: Sat, 27 Jun 2015 11:59:21 -0400 Subject: [PATCH 01/28] Hey, I made a change. --- TodoList/TodoList/main.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 187be40..73d445b 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -11,7 +11,7 @@ int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... - NSLog(@"Hello, World!"); + NSLog(@"Hello, Party!"); } return 0; } From 9d7db5a584ca1e62ca275cf0410f0b604b49a5d1 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Sat, 27 Jun 2015 12:05:15 -0400 Subject: [PATCH 02/28] I changed something --- TodoList/TodoList/main.m | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 73d445b..03f107b 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -10,8 +10,11 @@ int main(int argc, const char * argv[]) { @autoreleasepool { - // insert code here... - NSLog(@"Hello, Party!"); + // START CODE HERE + + + + // END CODE HERE } return 0; } From dc75a314d34d1e38b96fde8d859675060a8026bb Mon Sep 17 00:00:00 2001 From: Natalia Estrella Date: Sat, 27 Jun 2015 12:09:15 -0400 Subject: [PATCH 03/28] added something else --- TodoList/TodoList/main.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 03f107b..9f77b83 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -15,6 +15,8 @@ int main(int argc, const char * argv[]) { // END CODE HERE + +// or End code here } return 0; } From 65cccd5bb5a698316dd14d63b13087db8f8803d8 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Sat, 27 Jun 2015 13:57:35 -0400 Subject: [PATCH 04/28] added interface and implementation --- TodoList/TodoList/main.m | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 9f77b83..7648974 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -8,6 +8,16 @@ #import +@interface ManageItem : NSObject + +@end + +@implementation ManageItem + + +@end + + int main(int argc, const char * argv[]) { @autoreleasepool { // START CODE HERE @@ -15,8 +25,6 @@ int main(int argc, const char * argv[]) { // END CODE HERE - -// or End code here } return 0; } From 82485d1f19104599c83d7fb58c2257c746bd60e3 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Sat, 27 Jun 2015 14:10:09 -0400 Subject: [PATCH 05/28] added property --- TodoList/TodoList/main.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 7648974..aede243 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -9,6 +9,13 @@ #import @interface ManageItem : NSObject +@property (nonatomic) NSString *markItem; +@property (nonatomic) int priorityItem; +@property (nonatomic) BOOL markDoneItem; +@property (nonatomic) NSString *addItem; +@property (nonatomic) NSString *deletItem; + + @end From c68af5387b1c246ac0bee52011173ebe176cee33 Mon Sep 17 00:00:00 2001 From: Natalia Estrella Date: Sat, 27 Jun 2015 14:53:30 -0400 Subject: [PATCH 06/28] changed --- TodoList/TodoList/main.m | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index aede243..b80c7ea 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -8,18 +8,32 @@ #import -@interface ManageItem : NSObject -@property (nonatomic) NSString *markItem; -@property (nonatomic) int priorityItem; -@property (nonatomic) BOOL markDoneItem; -@property (nonatomic) NSString *addItem; -@property (nonatomic) NSString *deletItem; +@interface Item : NSObject { + NSString *xyz; +} +@property (nonatomic) NSString *itemContent; +@property (nonatomic) int *itemPriority; +-(void)setXYZ:(NSString *)value; +-(NSString *)xyz; +@end +//@interface ManageItem : NSObject +//@property (nonatomic) NSString *markItem; +//@property (nonatomic) int priorityItem; +//@property (nonatomic) BOOL markDoneItem; +//@property (nonatomic) NSString *addItem; +//@property (nonatomic) NSString *deletItem; +// +// +// +//@end -@end +@implementation Item -@implementation ManageItem +- (void)setXYZ:(NSString *)value { + _xyx = value; +} @end @@ -29,7 +43,8 @@ int main(int argc, const char * argv[]) { @autoreleasepool { // START CODE HERE - + Item *aItem = [Item new]; + aItem // END CODE HERE } From 2028032d7e2272a76fa32ec560e7b832b72829fd Mon Sep 17 00:00:00 2001 From: Natalia Estrella Date: Sat, 27 Jun 2015 14:56:06 -0400 Subject: [PATCH 07/28] changed something --- TodoList/TodoList/main.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index b80c7ea..f15a41a 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -25,8 +25,6 @@ -(NSString *)xyz; //@property (nonatomic) NSString *addItem; //@property (nonatomic) NSString *deletItem; // -// -// //@end @implementation Item From 9100050f2041237e4cf310dc737abbaa593a2eb6 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Sat, 27 Jun 2015 15:38:33 -0400 Subject: [PATCH 08/28] new --- TodoList/TodoList/main.m | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index f15a41a..46297a3 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -8,29 +8,22 @@ #import -@interface Item : NSObject { - NSString *xyz; -} -@property (nonatomic) NSString *itemContent; -@property (nonatomic) int *itemPriority; --(void)setXYZ:(NSString *)value; --(NSString *)xyz; + +@interface Item : NSObject + +@property (nonatomic) NSString *content; +-(NSString *)inputContentItem; @end -//@interface ManageItem : NSObject -//@property (nonatomic) NSString *markItem; -//@property (nonatomic) int priorityItem; -//@property (nonatomic) BOOL markDoneItem; -//@property (nonatomic) NSString *addItem; -//@property (nonatomic) NSString *deletItem; -// -//@end -@implementation Item -- (void)setXYZ:(NSString *)value { - _xyx = value; + + + +@implementation Item +-(NSString *)inputContentItem { + scanf(@"%@", intputContentItem); } @@ -40,9 +33,7 @@ - (void)setXYZ:(NSString *)value { int main(int argc, const char * argv[]) { @autoreleasepool { // START CODE HERE - - Item *aItem = [Item new]; - aItem + // END CODE HERE } From 44bf3063214f35a90e59d5a9e53fc047c6f2e214 Mon Sep 17 00:00:00 2001 From: Natalia Estrella Date: Sun, 28 Jun 2015 10:45:54 -0400 Subject: [PATCH 09/28] Made changes to interface and priority. --- TodoList/TodoList/main.m | 101 +++++++++++++++++++++++++++++++++++---- 1 file changed, 93 insertions(+), 8 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 46297a3..426c0f2 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -8,34 +8,119 @@ #import - - @interface Item : NSObject @property (nonatomic) NSString *content; --(NSString *)inputContentItem; +@property (nonatomic) int itemPriority; + +//-(void)setContent:(NSString *)contentInfo andPriority: (int)contentPriority; +-(instancetype)initWithContent:(NSString *)contentInfo priority: (int)contentPriority; + +@end + +@interface List : NSObject +//turn this item array of type item into a mutable array in implenetation? +@property (nonatomic) NSMutableArray *items; +@property (nonatomic) NSString *listName; +@property (nonatomic) int listPriority; +@property (nonatomic) BOOL completed; + + +-(void)setListPriority:(int)listPriority; +-(void)removeListItem:(int)itemIndex; +-(void)scanItem; + @end +@interface Manager : NSObject +@property (nonatomic) NSMutableArray *lists; +-(void)addList:(List *)list; +@end @implementation Item --(NSString *)inputContentItem { - scanf(@"%@", intputContentItem); + +- (instancetype)initWithContent:(NSString *)contentInfo priority:(int)contentPriority +{ + self = [super init]; + if (self) { + self.content = contentInfo; + self.itemPriority = contentPriority; + } + return self; +} + +-(NSString *)description +{ + return self.content; +} + +@end + +@implementation List + +- (instancetype)init +{ + self = [super init]; + if (self) { + self.items = [NSMutableArray array]; + } + return self; +} + +-(void)setListPriority:(int)listPriority +{ + +} + +-(void)removeListItem:(int)itemIndex +{ + } +-(void)scanItem +{ + char inputText[256]; + scanf("%s", inputText); + Item *item = [[Item alloc] initWithContent:@(inputText) priority:(int)self.items.count]; + [self.items addObject:item]; +} +-(NSString *)description +{ + return [NSString stringWithFormat:@"%@", self.items]; +} @end +@implementation Manager + +-(void)addList:(List *)list +{ + +} + +@end + + + int main(int argc, const char * argv[]) { @autoreleasepool { - // START CODE HERE - - // END CODE HERE + +// Item *newItem = [[Item alloc]init]; +// [newItem setContent:@"puppy" andPriority:1]; +// Item *newItem = [[Item alloc] initWithContent:@"puppy" priority:1]; +// +// +// List *list = [[List alloc] init]; +// [list scanItem]; +// [list scanItem]; +// printf("%s\n", [[NSString stringWithFormat:@"%@", list] UTF8String]); + } return 0; } From 6163bf47ff51f8cf040a317e7e018e7bfc8f8dd9 Mon Sep 17 00:00:00 2001 From: Natalia Estrella Date: Sun, 28 Jun 2015 11:44:39 -0400 Subject: [PATCH 10/28] Arrays with Cameron --- TodoList/TodoList/main.m | 77 +++++++--------------------------------- 1 file changed, 13 insertions(+), 64 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 426c0f2..90d8577 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -10,11 +10,10 @@ @interface Item : NSObject -@property (nonatomic) NSString *content; +@property (nonatomic) NSString *itemContent; @property (nonatomic) int itemPriority; +@property (nonatomic) BOOL itemCompleted; -//-(void)setContent:(NSString *)contentInfo andPriority: (int)contentPriority; --(instancetype)initWithContent:(NSString *)contentInfo priority: (int)contentPriority; @end @@ -23,7 +22,6 @@ @interface List : NSObject @property (nonatomic) NSMutableArray *items; @property (nonatomic) NSString *listName; @property (nonatomic) int listPriority; -@property (nonatomic) BOOL completed; -(void)setListPriority:(int)listPriority; @@ -39,88 +37,39 @@ -(void)addList:(List *)list; @end - - @implementation Item -- (instancetype)initWithContent:(NSString *)contentInfo priority:(int)contentPriority -{ - self = [super init]; - if (self) { - self.content = contentInfo; - self.itemPriority = contentPriority; - } - return self; -} - --(NSString *)description -{ - return self.content; -} - @end @implementation List -- (instancetype)init +- (id)init { - self = [super init]; - if (self) { - self.items = [NSMutableArray array]; - } + // create items array here return self; } --(void)setListPriority:(int)listPriority -{ - -} - --(void)removeListItem:(int)itemIndex -{ - -} - --(void)scanItem -{ - char inputText[256]; - scanf("%s", inputText); - Item *item = [[Item alloc] initWithContent:@(inputText) priority:(int)self.items.count]; - [self.items addObject:item]; -} - --(NSString *)description -{ - return [NSString stringWithFormat:@"%@", self.items]; -} @end @implementation Manager --(void)addList:(List *)list +- (id)init { - + [self setLists:[[NSMutableArray alloc]init]]; + return self; } - @end - - - int main(int argc, const char * argv[]) { @autoreleasepool { + Item *puppyItem = [[Item alloc] init]; + puppyItem.itemContent = @"Buy a puppy"; + puppyItem.itemPriority = 4; + List *myList = [[List alloc] init]; -// Item *newItem = [[Item alloc]init]; -// [newItem setContent:@"puppy" andPriority:1]; -// Item *newItem = [[Item alloc] initWithContent:@"puppy" priority:1]; -// -// -// List *list = [[List alloc] init]; -// [list scanItem]; -// [list scanItem]; -// printf("%s\n", [[NSString stringWithFormat:@"%@", list] UTF8String]); - + // this won't do anything unless `items` is initialized + [myList.items addObject:puppyItem]; } return 0; } From 75043952c795d8b07159895ad55f480ecd07e9e4 Mon Sep 17 00:00:00 2001 From: Natalia Estrella Date: Sun, 28 Jun 2015 11:50:46 -0400 Subject: [PATCH 11/28] small changes --- TodoList/TodoList/main.m | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 90d8577..8c7a535 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -45,7 +45,7 @@ @implementation List - (id)init { - // create items array here + [self setItems:[[NSMutableArray alloc]init]]; return self; } @@ -62,14 +62,17 @@ - (id)init int main(int argc, const char * argv[]) { @autoreleasepool { - Item *puppyItem = [[Item alloc] init]; - puppyItem.itemContent = @"Buy a puppy"; - puppyItem.itemPriority = 4; + Item *coffeeItem = [[Item alloc] init]; + coffeeItem.itemContent = @"Buy coffee"; + coffeeItem.itemPriority = 4; + + List *groceryList = [[List alloc] init]; - List *myList = [[List alloc] init]; // this won't do anything unless `items` is initialized - [myList.items addObject:puppyItem]; + [groceryList.items addObject:coffeeItem]; + + } return 0; } From 76074701013722791a12f1b25cb4589bc81403c5 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Sun, 28 Jun 2015 12:10:15 -0400 Subject: [PATCH 12/28] bool --- TodoList/TodoList/main.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 8c7a535..f79f4e4 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -39,6 +39,15 @@ -(void)addList:(List *)list; @implementation Item +-(BOOL) itemCompleted { + NSLog(@"Mark Item Complete"); + char pickComplete; + scanf("%d",&pickComplete); + if (pickComplete == c) { + + } +} + @end @implementation List From 6c49738e0d6cefe8a65a600d37a913e111e526d8 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Sun, 28 Jun 2015 12:58:24 -0400 Subject: [PATCH 13/28] this might work --- TodoList/TodoList/main.m | 101 ++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 49 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index f79f4e4..f14e532 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -8,78 +8,81 @@ #import -@interface Item : NSObject - -@property (nonatomic) NSString *itemContent; -@property (nonatomic) int itemPriority; -@property (nonatomic) BOOL itemCompleted; - - -@end - -@interface List : NSObject -//turn this item array of type item into a mutable array in implenetation? -@property (nonatomic) NSMutableArray *items; -@property (nonatomic) NSString *listName; -@property (nonatomic) int listPriority; - - --(void)setListPriority:(int)listPriority; --(void)removeListItem:(int)itemIndex; --(void)scanItem; - -@end +BOOL notQuit = 1; @interface Manager : NSObject -@property (nonatomic) NSMutableArray *lists; --(void)addList:(List *)list; +-(void) mainMenu; +-(void) storeList; +-(void) addItem; +-(void) deleteItem; + @end -@implementation Item +@implementation Manager { + NSMutableArray *itemList; + NSString *userADDItem; +} --(BOOL) itemCompleted { - NSLog(@"Mark Item Complete"); - char pickComplete; - scanf("%d",&pickComplete); - if (pickComplete == c) { - +-(void) mainMenu { + NSLog(@"Add/Delete items: a/d"); + char mainMenuChoice; + scanf ("%c", &mainMenuChoice); + fpurge(stdin); + if (mainMenuChoice == 'a') { + [self addItem]; + } else if (mainMenuChoice =='d') { + [self deleteItem]; + } else if (mainMenuChoice == 'q') { + notQuit = 0; + } else { + NSLog(@"Invalid Entry"); } } -@end +-(void) storeList { + itemList = [[NSMutableArray alloc] init]; +} -@implementation List +-(void) addItem { + char addItem[256]; + NSLog(@"Add/Delete/Quit"); + gets(addItem); + userADDItem = [NSString stringWithCString:addItem encoding:1]; + [itemList addObject:userADDItem]; + NSLog(@"%@", itemList); + +} -- (id)init -{ - [self setItems:[[NSMutableArray alloc]init]]; - return self; +-(void) deleteItem { + NSLog(@"Which Item would you like to delete?"); + int udi; + int userDeleteItem = udi+1; + scanf("%d",&udi); + fpurge(stdin); + [itemList removeObjectAtIndex:userDeleteItem]; + NSLog(@"%@", itemList); } @end -@implementation Manager -- (id)init -{ - [self setLists:[[NSMutableArray alloc]init]]; - return self; -} -@end + int main(int argc, const char * argv[]) { @autoreleasepool { - Item *coffeeItem = [[Item alloc] init]; - coffeeItem.itemContent = @"Buy coffee"; - coffeeItem.itemPriority = 4; + + Manager *listManager = [[Manager alloc] init]; + [listManager storeList]; - List *groceryList = [[List alloc] init]; + while (notQuit) { + [listManager mainMenu]; + } - // this won't do anything unless `items` is initialized - [groceryList.items addObject:coffeeItem]; +// [listManager addItem]; +// [listManager deleteItem]; } From d0dd2011f0bc14cd847da276224c61c3a1405e67 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Sun, 28 Jun 2015 14:28:01 -0400 Subject: [PATCH 14/28] improved user input --- TodoList/TodoList/main.m | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index f14e532..7e93fe0 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -27,14 +27,26 @@ @implementation Manager { -(void) mainMenu { NSLog(@"Add/Delete items: a/d"); - char mainMenuChoice; - scanf ("%c", &mainMenuChoice); - fpurge(stdin); - if (mainMenuChoice == 'a') { + +// char mainMenuChoice; +// scanf ("%c", &mainMenuChoice); +// fpurge(stdin); + + + NSFileHandle *standardInput = [NSFileHandle fileHandleWithStandardInput]; + NSString *inputLine = [[[NSString alloc] initWithData:standardInput.availableData encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; +// NSString *mainMenuChoice = inputLine; + + + // check if the input length is 1 + // if so, check if the character is 'd', or 'q' + // otherwise, treat the input line as a new item + + if ([inputLine isEqualToString: @"add"]) { [self addItem]; - } else if (mainMenuChoice =='d') { + } else if ([inputLine isEqualToString: @"delete"]) { [self deleteItem]; - } else if (mainMenuChoice == 'q') { + } else if ([inputLine isEqualToString: @"quit"]){ notQuit = 0; } else { NSLog(@"Invalid Entry"); @@ -76,15 +88,10 @@ int main(int argc, const char * argv[]) { Manager *listManager = [[Manager alloc] init]; [listManager storeList]; - while (notQuit) { [listManager mainMenu]; } -// [listManager addItem]; -// [listManager deleteItem]; - - } return 0; } From 87049bf7359b97f07a3c1d2ebf371ec41e91dad9 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Sun, 28 Jun 2015 14:30:38 -0400 Subject: [PATCH 15/28] changed something --- TodoList/TodoList/main.m | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 7e93fe0..18dce72 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -28,14 +28,11 @@ @implementation Manager { -(void) mainMenu { NSLog(@"Add/Delete items: a/d"); -// char mainMenuChoice; -// scanf ("%c", &mainMenuChoice); -// fpurge(stdin); - NSFileHandle *standardInput = [NSFileHandle fileHandleWithStandardInput]; NSString *inputLine = [[[NSString alloc] initWithData:standardInput.availableData encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; -// NSString *mainMenuChoice = inputLine; + inputLine = [inputLine lowercaseString]; + // check if the input length is 1 From 776cf585d7d66dd12cf2939bc3dd3f28da94fa56 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Sun, 28 Jun 2015 14:32:12 -0400 Subject: [PATCH 16/28] another change --- TodoList/TodoList/main.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 18dce72..be5a7bd 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -26,7 +26,7 @@ @implementation Manager { } -(void) mainMenu { - NSLog(@"Add/Delete items: a/d"); + NSLog(@"Add/Delete/Quit items: "); NSFileHandle *standardInput = [NSFileHandle fileHandleWithStandardInput]; From a2bbd9abe1390c3b580f29827cd9e35c34573c32 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Sun, 28 Jun 2015 15:36:41 -0400 Subject: [PATCH 17/28] updated the user input loop --- TodoList/TodoList/main.m | 64 ++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index be5a7bd..6d9f8bd 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -28,26 +28,26 @@ @implementation Manager { -(void) mainMenu { NSLog(@"Add/Delete/Quit items: "); - - NSFileHandle *standardInput = [NSFileHandle fileHandleWithStandardInput]; - NSString *inputLine = [[[NSString alloc] initWithData:standardInput.availableData encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; - inputLine = [inputLine lowercaseString]; - - - - // check if the input length is 1 - // if so, check if the character is 'd', or 'q' - // otherwise, treat the input line as a new item - - if ([inputLine isEqualToString: @"add"]) { - [self addItem]; - } else if ([inputLine isEqualToString: @"delete"]) { - [self deleteItem]; - } else if ([inputLine isEqualToString: @"quit"]){ - notQuit = 0; - } else { - NSLog(@"Invalid Entry"); + while (notQuit) { + + NSFileHandle *standardInput = [NSFileHandle fileHandleWithStandardInput]; + NSString *inputLine = [[[NSString alloc] initWithData:standardInput.availableData encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + inputLine = [inputLine lowercaseString]; + + + if ([inputLine isEqualToString: @"add"]) { + [self addItem]; + notQuit = 1; + } else if ([inputLine isEqualToString: @"delete"]) { + [self deleteItem]; + notQuit = 1; + } else if ([inputLine isEqualToString: @"quit"]){ + notQuit = 0; + } else { + NSLog(@"Invalid Entry"); + } } + } -(void) storeList { @@ -55,12 +55,26 @@ -(void) storeList { } -(void) addItem { - char addItem[256]; - NSLog(@"Add/Delete/Quit"); - gets(addItem); - userADDItem = [NSString stringWithCString:addItem encoding:1]; - [itemList addObject:userADDItem]; - NSLog(@"%@", itemList); + + + BOOL addNotQuit = 1; + + while (addNotQuit) { + NSFileHandle *standardInput = [NSFileHandle fileHandleWithStandardInput]; + NSString *uADDItem = [[[NSString alloc] initWithData:standardInput.availableData encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + + if ([uADDItem isEqualToString:@"quit"]) { + addNotQuit = 0; + } else if ([uADDItem isEqualToString:@"delete"]) { + [self deleteItem]; + } else { + [itemList addObject:uADDItem]; + NSLog(@"%@", itemList); + } + } + + + } From ed0bccc851fb9cce46e1c1885f74cdfa02acbddc Mon Sep 17 00:00:00 2001 From: Natalia Estrella Date: Mon, 29 Jun 2015 23:32:20 -0400 Subject: [PATCH 18/28] Hey, this looks like a solid start :) --- TodoList/TodoList/main.m | 124 +++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 70 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 6d9f8bd..64304ad 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -1,108 +1,92 @@ // // 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 -BOOL notQuit = 1; +@interface Item : NSObject + +@property (nonatomic) NSString *content; +@property (nonatomic) int priority; + +@end + +@interface List : NSObject + +@property (nonatomic) NSMutableArray *items; +@property (nonatomic) NSString *title; +@property (nonatomic) int priority; + +-(void)enterItem; + +@end @interface Manager : NSObject --(void) mainMenu; --(void) storeList; --(void) addItem; --(void) deleteItem; +@property (nonatomic) NSMutableArray *lists; +-(void)start; @end -@implementation Manager { - NSMutableArray *itemList; - NSString *userADDItem; +@implementation Item + +@end + +@implementation List + +-(void)enterItem { } --(void) mainMenu { - NSLog(@"Add/Delete/Quit items: "); - - while (notQuit) { - - NSFileHandle *standardInput = [NSFileHandle fileHandleWithStandardInput]; - NSString *inputLine = [[[NSString alloc] initWithData:standardInput.availableData encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; - inputLine = [inputLine lowercaseString]; - - - if ([inputLine isEqualToString: @"add"]) { - [self addItem]; - notQuit = 1; - } else if ([inputLine isEqualToString: @"delete"]) { - [self deleteItem]; - notQuit = 1; - } else if ([inputLine isEqualToString: @"quit"]){ - notQuit = 0; - } else { - NSLog(@"Invalid Entry"); - } - } +@end +@implementation Manager + +-(List *)createList { + List *newList = [[List alloc] init]; + [self.lists addObject:newList]; + return newList; + } --(void) storeList { - itemList = [[NSMutableArray alloc] init]; +-(void)printMenu { + printf("Choose form the following:\n"); + printf("1. Create List\n"); + printf("2. Print all lists\n"); } --(void) addItem { +-(int)getInput { + [self printMenu]; + int x; + scanf("%d", &x); + return x; +} - - BOOL addNotQuit = 1; - - while (addNotQuit) { - NSFileHandle *standardInput = [NSFileHandle fileHandleWithStandardInput]; - NSString *uADDItem = [[[NSString alloc] initWithData:standardInput.availableData encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; - - if ([uADDItem isEqualToString:@"quit"]) { - addNotQuit = 0; - } else if ([uADDItem isEqualToString:@"delete"]) { - [self deleteItem]; - } else { - [itemList addObject:uADDItem]; - NSLog(@"%@", itemList); +-(void)start { + while (true) { + int input = [self getInput]; + if (input == 1) { + List *newList = [self createList]; + } } - - } --(void) deleteItem { - NSLog(@"Which Item would you like to delete?"); - int udi; - int userDeleteItem = udi+1; - scanf("%d",&udi); - fpurge(stdin); - [itemList removeObjectAtIndex:userDeleteItem]; - NSLog(@"%@", itemList); -} @end - - int main(int argc, const char * argv[]) { @autoreleasepool { - - Manager *listManager = [[Manager alloc] init]; - [listManager storeList]; - - while (notQuit) { - [listManager mainMenu]; - } + Manager *manager = [[Manager alloc] init]; + [manager start]; } return 0; } From ed5e1f5d1cc52feb95b570a3aa4b2ddc3eed352d Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Tue, 30 Jun 2015 01:09:28 -0400 Subject: [PATCH 19/28] added three class in different files --- TodoList/TodoList.xcodeproj/project.pbxproj | 19 +++++++++++++++++++ TodoList/TodoList/Item.h | 13 +++++++++++++ TodoList/TodoList/Item.m | 13 +++++++++++++ TodoList/TodoList/List.h | 13 +++++++++++++ TodoList/TodoList/List.m | 13 +++++++++++++ TodoList/TodoList/Manager.h | 13 +++++++++++++ TodoList/TodoList/Manager.m | 13 +++++++++++++ 7 files changed, 97 insertions(+) create mode 100644 TodoList/TodoList/Item.h create mode 100644 TodoList/TodoList/Item.m create mode 100644 TodoList/TodoList/List.h create mode 100644 TodoList/TodoList/List.m create mode 100644 TodoList/TodoList/Manager.h create mode 100644 TodoList/TodoList/Manager.m 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..14b2615 --- /dev/null +++ b/TodoList/TodoList/Item.h @@ -0,0 +1,13 @@ +// +// Item.h +// TodoList +// +// Created by Jason Wang on 6/30/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface Item : NSObject + +@end diff --git a/TodoList/TodoList/Item.m b/TodoList/TodoList/Item.m new file mode 100644 index 0000000..baf510d --- /dev/null +++ b/TodoList/TodoList/Item.m @@ -0,0 +1,13 @@ +// +// Item.m +// TodoList +// +// Created by Jason Wang on 6/30/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "Item.h" + +@implementation Item + +@end diff --git a/TodoList/TodoList/List.h b/TodoList/TodoList/List.h new file mode 100644 index 0000000..5b519e4 --- /dev/null +++ b/TodoList/TodoList/List.h @@ -0,0 +1,13 @@ +// +// List.h +// TodoList +// +// Created by Jason Wang on 6/30/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface List : NSObject + +@end diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m new file mode 100644 index 0000000..50298b9 --- /dev/null +++ b/TodoList/TodoList/List.m @@ -0,0 +1,13 @@ +// +// List.m +// TodoList +// +// Created by Jason Wang on 6/30/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "List.h" + +@implementation List + +@end diff --git a/TodoList/TodoList/Manager.h b/TodoList/TodoList/Manager.h new file mode 100644 index 0000000..5159eca --- /dev/null +++ b/TodoList/TodoList/Manager.h @@ -0,0 +1,13 @@ +// +// Manager.h +// TodoList +// +// Created by Jason Wang on 6/30/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import + +@interface Manager : NSObject + +@end diff --git a/TodoList/TodoList/Manager.m b/TodoList/TodoList/Manager.m new file mode 100644 index 0000000..ddc1aba --- /dev/null +++ b/TodoList/TodoList/Manager.m @@ -0,0 +1,13 @@ +// +// Manager.m +// TodoList +// +// Created by Jason Wang on 6/30/15. +// Copyright (c) 2015 Mike Kavouras. All rights reserved. +// + +#import "Manager.h" + +@implementation Manager + +@end From 89982e4334b43e96c16b5aeeb96b82188de420ab Mon Sep 17 00:00:00 2001 From: Natalia Estrella Date: Tue, 30 Jun 2015 01:48:25 -0400 Subject: [PATCH 20/28] Creating list and items are functional --- TodoList/TodoList/main.m | 157 ++++++++++++++++++++++++++++++++++----- 1 file changed, 139 insertions(+), 18 deletions(-) diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index 64304ad..f71575e 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -21,7 +21,8 @@ @interface List : NSObject @property (nonatomic) NSString *title; @property (nonatomic) int priority; --(void)enterItem; +-(Item *)enterItem; +-(void)showMenu; @end @@ -29,53 +30,174 @@ @interface Manager : NSObject @property (nonatomic) NSMutableArray *lists; --(void)start; ++(NSString *)getInputString; ++(void)printString:(NSString *)string; + +-(void)showMenu; @end @implementation Item +- (instancetype)initWithContent:(NSString *)content priority:(int)priority +{ + self = [super init]; + if (self) { + self.content = content; + self.priority = priority; + } + return self; +} + +-(NSString *)description +{ + return [NSString stringWithFormat:@"(Priority %@) %@", @(self.priority), self.content]; +} + @end @implementation List --(void)enterItem { +- (instancetype)init +{ + self = [super init]; + if (self) { + self.items = [[NSMutableArray alloc] init]; + } + return self; +} + +-(Item *)enterItem { + [Manager printString:@"Enter task:"]; + NSString *task = [Manager getInputString]; + // If the user inputs nothing, return no item (nil) + if (task.length == 0) { + return nil; + } + + [Manager printString:@"Enter priority (1 - 4):"]; + int priority = [Manager getInputString].intValue; + + Item *newItem = [[Item alloc] initWithContent:task priority:priority]; + [self.items addObject:newItem]; + + return newItem; +} + +-(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:@"Submenu for %@ list. Choose form the following:", self.title]]; + [Manager printString:@"1. Add Item"]; + [Manager printString:@"2. Print list"]; + [Manager printString:@"0. Main menu"]; +} + +-(int)getMenuInput { + [self printMenu]; + return [Manager getInputString].intValue; } +-(void)showMenu { + while (true) { + int input = [self getMenuInput]; + if (input == 0) { + break; + } + else if (input == 1) { + [self enterItem]; + } + else if (input == 2) { + [Manager printString:self.description]; + } + } +} + + @end @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'; + + NSString *output = [NSString stringWithUTF8String:input]; + return output; +} + ++(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 { - printf("Choose form the following:\n"); - printf("1. Create List\n"); - printf("2. Print all lists\n"); + [Manager printString:@"Main menu. Choose form the following:"]; + [Manager printString:@"1. Create List"]; + [Manager printString:@"2. Print all lists"]; + [Manager printString:@"0. Exit"]; } --(int)getInput { +-(int)getMenuInput { [self printMenu]; - int x; - scanf("%d", &x); - return x; + return [Manager getInputString].intValue; } --(void)start { +-(void)printLists { + for (List *list in self.lists) { + [Manager printString:list.description]; + } +} + +-(void)showMenu { while (true) { - int input = [self getInput]; - if (input == 1) { + int input = [self getMenuInput]; + if (input == 0) { + break; + } + else if (input == 1) { List *newList = [self createList]; - + [newList showMenu]; + } + else if (input == 2) { + [self printLists]; } } - - } @@ -84,9 +206,8 @@ -(void)start { int main(int argc, const char * argv[]) { @autoreleasepool { - Manager *manager = [[Manager alloc] init]; - [manager start]; + [manager showMenu]; } return 0; } From e9eb2ab5657eedbd3e275f4d574201ac86e2de70 Mon Sep 17 00:00:00 2001 From: Natalia Estrella Date: Tue, 30 Jun 2015 01:56:21 -0400 Subject: [PATCH 21/28] Implement the classes in separate files --- TodoList/TodoList/Item.h | 5 + TodoList/TodoList/Item.m | 15 +++ TodoList/TodoList/List.h | 8 ++ TodoList/TodoList/List.m | 66 ++++++++++++ TodoList/TodoList/Manager.h | 7 ++ TodoList/TodoList/Manager.m | 74 ++++++++++++++ TodoList/TodoList/main.m | 197 +----------------------------------- 7 files changed, 176 insertions(+), 196 deletions(-) diff --git a/TodoList/TodoList/Item.h b/TodoList/TodoList/Item.h index 14b2615..1355d19 100644 --- a/TodoList/TodoList/Item.h +++ b/TodoList/TodoList/Item.h @@ -10,4 +10,9 @@ @interface Item : NSObject +@property (nonatomic) NSString *content; +@property (nonatomic) int priority; + +- (instancetype)initWithContent:(NSString *)content priority:(int)priority; + @end diff --git a/TodoList/TodoList/Item.m b/TodoList/TodoList/Item.m index baf510d..3b8cc79 100644 --- a/TodoList/TodoList/Item.m +++ b/TodoList/TodoList/Item.m @@ -10,4 +10,19 @@ @implementation Item +- (instancetype)initWithContent:(NSString *)content priority:(int)priority +{ + self = [super init]; + if (self) { + self.content = content; + self.priority = priority; + } + return self; +} + +-(NSString *)description +{ + return [NSString stringWithFormat:@"(Priority %@) %@", @(self.priority), self.content]; +} + @end diff --git a/TodoList/TodoList/List.h b/TodoList/TodoList/List.h index 5b519e4..f302ba7 100644 --- a/TodoList/TodoList/List.h +++ b/TodoList/TodoList/List.h @@ -7,7 +7,15 @@ // #import +#import "Item.h" @interface List : NSObject +@property (nonatomic) NSMutableArray *items; +@property (nonatomic) NSString *title; +@property (nonatomic) int priority; + +-(Item *)enterItem; +-(void)showMenu; + @end diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index 50298b9..26e5e59 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -7,7 +7,73 @@ // #import "List.h" +#import "Manager.h" @implementation List +- (instancetype)init +{ + self = [super init]; + if (self) { + self.items = [[NSMutableArray alloc] init]; + } + return self; +} + +-(Item *)enterItem { + [Manager printString:@"Enter task:"]; + NSString *task = [Manager getInputString]; + // If the user inputs nothing, return no item (nil) + if (task.length == 0) { + return nil; + } + + [Manager printString:@"Enter priority (1 - 4):"]; + int priority = [Manager getInputString].intValue; + + Item *newItem = [[Item alloc] initWithContent:task priority:priority]; + [self.items addObject:newItem]; + + return newItem; +} + +-(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:@"Submenu for %@ list. Choose form the following:", self.title]]; + [Manager printString:@"1. Add Item"]; + [Manager printString:@"2. Print list"]; + [Manager printString:@"99. Main menu"]; +} + +-(int)getMenuInput { + [self printMenu]; + return [Manager getInputString].intValue; +} + +-(void)showMenu { + while (true) { + int input = [self getMenuInput]; + if (input == 99) { + break; + } + else if (input == 1) { + [self enterItem]; + } + else if (input == 2) { + [Manager printString:self.description]; + } + } +} + @end diff --git a/TodoList/TodoList/Manager.h b/TodoList/TodoList/Manager.h index 5159eca..a2aa375 100644 --- a/TodoList/TodoList/Manager.h +++ b/TodoList/TodoList/Manager.h @@ -10,4 +10,11 @@ @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 index ddc1aba..fa27ec9 100644 --- a/TodoList/TodoList/Manager.m +++ b/TodoList/TodoList/Manager.m @@ -7,7 +7,81 @@ // #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'; + + NSString *output = [NSString stringWithUTF8String:input]; + return output; +} + ++(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. Create List"]; + [Manager printString:@"2. Print all lists"]; + [Manager printString:@"99. Exit"]; +} + +-(int)getMenuInput { + [self printMenu]; + return [Manager getInputString].intValue; +} + +-(void)printLists { + for (List *list in self.lists) { + [Manager printString:list.description]; + } +} + +-(void)showMenu { + while (true) { + int input = [self getMenuInput]; + if (input == 99) { + break; + } + else if (input == 1) { + List *newList = [self createList]; + [newList showMenu]; + } + else if (input == 2) { + [self printLists]; + } + } +} + + @end diff --git a/TodoList/TodoList/main.m b/TodoList/TodoList/main.m index f71575e..171147f 100644 --- a/TodoList/TodoList/main.m +++ b/TodoList/TodoList/main.m @@ -7,202 +7,7 @@ // #import - -@interface Item : NSObject - -@property (nonatomic) NSString *content; -@property (nonatomic) int priority; - -@end - -@interface List : NSObject - -@property (nonatomic) NSMutableArray *items; -@property (nonatomic) NSString *title; -@property (nonatomic) int priority; - --(Item *)enterItem; --(void)showMenu; - -@end - -@interface Manager : NSObject - -@property (nonatomic) NSMutableArray *lists; - -+(NSString *)getInputString; -+(void)printString:(NSString *)string; - --(void)showMenu; - -@end - -@implementation Item - -- (instancetype)initWithContent:(NSString *)content priority:(int)priority -{ - self = [super init]; - if (self) { - self.content = content; - self.priority = priority; - } - return self; -} - --(NSString *)description -{ - return [NSString stringWithFormat:@"(Priority %@) %@", @(self.priority), self.content]; -} - -@end - -@implementation List - -- (instancetype)init -{ - self = [super init]; - if (self) { - self.items = [[NSMutableArray alloc] init]; - } - return self; -} - --(Item *)enterItem { - [Manager printString:@"Enter task:"]; - NSString *task = [Manager getInputString]; - // If the user inputs nothing, return no item (nil) - if (task.length == 0) { - return nil; - } - - [Manager printString:@"Enter priority (1 - 4):"]; - int priority = [Manager getInputString].intValue; - - Item *newItem = [[Item alloc] initWithContent:task priority:priority]; - [self.items addObject:newItem]; - - return newItem; -} - --(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:@"Submenu for %@ list. Choose form the following:", self.title]]; - [Manager printString:@"1. Add Item"]; - [Manager printString:@"2. Print list"]; - [Manager printString:@"0. Main menu"]; -} - --(int)getMenuInput { - [self printMenu]; - return [Manager getInputString].intValue; -} - --(void)showMenu { - while (true) { - int input = [self getMenuInput]; - if (input == 0) { - break; - } - else if (input == 1) { - [self enterItem]; - } - else if (input == 2) { - [Manager printString:self.description]; - } - } -} - - -@end - -@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'; - - NSString *output = [NSString stringWithUTF8String:input]; - return output; -} - -+(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. Create List"]; - [Manager printString:@"2. Print all lists"]; - [Manager printString:@"0. Exit"]; -} - --(int)getMenuInput { - [self printMenu]; - return [Manager getInputString].intValue; -} - --(void)printLists { - for (List *list in self.lists) { - [Manager printString:list.description]; - } -} - --(void)showMenu { - while (true) { - int input = [self getMenuInput]; - if (input == 0) { - break; - } - else if (input == 1) { - List *newList = [self createList]; - [newList showMenu]; - } - else if (input == 2) { - [self printLists]; - } - } -} - - -@end - +#import "Manager.h" int main(int argc, const char * argv[]) { @autoreleasepool { From 6217046407dc326d58b96d7c27902bc6757e4088 Mon Sep 17 00:00:00 2001 From: Natalia Estrella Date: Tue, 30 Jun 2015 02:07:39 -0400 Subject: [PATCH 22/28] Remove item implementation in progress --- TodoList/TodoList/List.h | 1 - TodoList/TodoList/List.m | 34 +++++++++++++++++++++++++--------- TodoList/TodoList/Manager.m | 14 +++++++------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/TodoList/TodoList/List.h b/TodoList/TodoList/List.h index f302ba7..cf6349c 100644 --- a/TodoList/TodoList/List.h +++ b/TodoList/TodoList/List.h @@ -15,7 +15,6 @@ @property (nonatomic) NSString *title; @property (nonatomic) int priority; --(Item *)enterItem; -(void)showMenu; @end diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index 26e5e59..2e56612 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -20,7 +20,7 @@ - (instancetype)init return self; } --(Item *)enterItem { +-(Item *)addItem { [Manager printString:@"Enter task:"]; NSString *task = [Manager getInputString]; // If the user inputs nothing, return no item (nil) @@ -37,6 +37,18 @@ -(Item *)enterItem { return newItem; } +-(void)removeItem { + [self printList]; + [Manager printString:@"Choose the index to remove:"]; + int removeIndex = [Manager getInputString].intValue-1; + // TODO Implement this! +} + +-(void)printList { + [Manager printString:self.description]; +} + + -(NSString *)description { NSMutableString *desc = [[NSMutableString alloc] init]; @@ -51,8 +63,9 @@ -(NSString *)description -(void)printMenu { [Manager printString:[NSString stringWithFormat:@"Submenu for %@ list. Choose form the following:", self.title]]; - [Manager printString:@"1. Add Item"]; - [Manager printString:@"2. Print list"]; + [Manager printString:@"1. Print list"]; + [Manager printString:@"2. Add Item"]; + [Manager printString:@"3. Remove Item"]; [Manager printString:@"99. Main menu"]; } @@ -64,14 +77,17 @@ -(int)getMenuInput { -(void)showMenu { while (true) { int input = [self getMenuInput]; - if (input == 99) { - break; - } - else if (input == 1) { - [self enterItem]; + if (input == 1) { + [self printList]; } else if (input == 2) { - [Manager printString:self.description]; + [self addItem]; + } + else if (input == 3) { + [self removeItem]; + } + else if (input == 99) { + break; } } } diff --git a/TodoList/TodoList/Manager.m b/TodoList/TodoList/Manager.m index fa27ec9..6226fc5 100644 --- a/TodoList/TodoList/Manager.m +++ b/TodoList/TodoList/Manager.m @@ -51,8 +51,8 @@ -(List *)createList { -(void)printMenu { [Manager printString:@"Main menu. Choose form the following:"]; - [Manager printString:@"1. Create List"]; - [Manager printString:@"2. Print all lists"]; + [Manager printString:@"1. Print all lists"]; + [Manager printString:@"2. Create List"]; [Manager printString:@"99. Exit"]; } @@ -70,15 +70,15 @@ -(void)printLists { -(void)showMenu { while (true) { int input = [self getMenuInput]; - if (input == 99) { - break; + if (input == 1) { + [self printLists]; } - else if (input == 1) { + else if (input == 2) { List *newList = [self createList]; [newList showMenu]; } - else if (input == 2) { - [self printLists]; + else if (input == 99) { + break; } } } From 909a50c6d5eebdbe2f86d778ca0598227a4eedfc Mon Sep 17 00:00:00 2001 From: Natalia Estrella Date: Wed, 1 Jul 2015 03:49:26 -0400 Subject: [PATCH 23/28] Edit feature completed :) --- TodoList/TodoList/List.h | 1 + TodoList/TodoList/List.m | 32 +++++++++++++++++++++++++++----- TodoList/TodoList/Manager.m | 3 +-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/TodoList/TodoList/List.h b/TodoList/TodoList/List.h index cf6349c..52787c7 100644 --- a/TodoList/TodoList/List.h +++ b/TodoList/TodoList/List.h @@ -17,4 +17,5 @@ -(void)showMenu; + @end diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index 2e56612..4a2600b 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -23,10 +23,6 @@ - (instancetype)init -(Item *)addItem { [Manager printString:@"Enter task:"]; NSString *task = [Manager getInputString]; - // If the user inputs nothing, return no item (nil) - if (task.length == 0) { - return nil; - } [Manager printString:@"Enter priority (1 - 4):"]; int priority = [Manager getInputString].intValue; @@ -34,14 +30,36 @@ -(Item *)addItem { 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; - // TODO Implement this! + [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]; + + [Manager printString:@"Enter priority (1 - 4):"]; + int priority = [Manager getInputString].intValue; + + + item.content = task; + item.priority = priority; + [self printList]; + } -(void)printList { @@ -66,6 +84,7 @@ -(void)printMenu { [Manager printString:@"1. Print list"]; [Manager printString:@"2. Add Item"]; [Manager printString:@"3. Remove Item"]; + [Manager printString:@"4. Edit Item"]; [Manager printString:@"99. Main menu"]; } @@ -86,6 +105,9 @@ -(void)showMenu { else if (input == 3) { [self removeItem]; } + else if (input == 4) { + [self editItem]; + } else if (input == 99) { break; } diff --git a/TodoList/TodoList/Manager.m b/TodoList/TodoList/Manager.m index 6226fc5..93fcde9 100644 --- a/TodoList/TodoList/Manager.m +++ b/TodoList/TodoList/Manager.m @@ -32,8 +32,7 @@ +(NSString *)getInputString { if (input[length] == '\n') input[length] = '\0'; - NSString *output = [NSString stringWithUTF8String:input]; - return output; + return [NSString stringWithUTF8String:input]; } +(void)printString:(NSString *)string { From c9ef55b18d8f0e4c7bacc734fa8d704f8bd77d5f Mon Sep 17 00:00:00 2001 From: Natalia Estrella Date: Wed, 1 Jul 2015 04:04:36 -0400 Subject: [PATCH 24/28] Made priority check. Also, learned about recursion! --- TodoList/TodoList/List.m | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index 4a2600b..91da20b 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -20,12 +20,26 @@ - (instancetype)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]; - [Manager printString:@"Enter priority (1 - 4):"]; - int priority = [Manager getInputString].intValue; + int priority = [self getPriority]; Item *newItem = [[Item alloc] initWithContent:task priority:priority]; [self.items addObject:newItem]; @@ -52,9 +66,7 @@ -(void)editItem { [Manager printString:@"Enter task:"]; NSString *task = [Manager getInputString]; - [Manager printString:@"Enter priority (1 - 4):"]; - int priority = [Manager getInputString].intValue; - + int priority = [self getPriority]; item.content = task; item.priority = priority; From 3d0a1b2f9eaf6ab7cb3bc65d56c10c2a38e6f1d6 Mon Sep 17 00:00:00 2001 From: Natalia Estrella Date: Wed, 1 Jul 2015 16:30:17 -0400 Subject: [PATCH 25/28] Added title to lists --- TodoList/TodoList/List.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index 91da20b..c1ee21b 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -84,7 +84,7 @@ -(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]]; + NSString *newLine = [NSString stringWithFormat:@"%@ %@: %@\n", self.title, @(i+1), self.items[i]]; [desc appendString:newLine]; } return desc; From 53743e3ac5135f89d640671bb42bd614e31c62ad Mon Sep 17 00:00:00 2001 From: Natalia Estrella Date: Wed, 1 Jul 2015 16:50:53 -0400 Subject: [PATCH 26/28] Changed list title --- TodoList/TodoList/List.m | 3 ++- TodoList/TodoList/Manager.m | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index c1ee21b..da3b51a 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -75,6 +75,7 @@ -(void)editItem { } -(void)printList { + [Manager printString:[NSString stringWithFormat:@"Title: %@", self.title]]; [Manager printString:self.description]; } @@ -84,7 +85,7 @@ -(NSString *)description NSMutableString *desc = [[NSMutableString alloc] init]; [desc appendString:@"\n"]; for (int i = 0; i < self.items.count; i++) { - NSString *newLine = [NSString stringWithFormat:@"%@ %@: %@\n", self.title, @(i+1), self.items[i]]; + NSString *newLine = [NSString stringWithFormat:@"%@: %@\n",@(i+1), self.items[i]]; [desc appendString:newLine]; } return desc; diff --git a/TodoList/TodoList/Manager.m b/TodoList/TodoList/Manager.m index 93fcde9..da64e8e 100644 --- a/TodoList/TodoList/Manager.m +++ b/TodoList/TodoList/Manager.m @@ -62,6 +62,7 @@ -(int)getMenuInput { -(void)printLists { for (List *list in self.lists) { + [Manager printString:list.title]; [Manager printString:list.description]; } } From b9adaef69e4035af470dd0cafe3caa2de274154e Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Wed, 1 Jul 2015 17:28:19 -0400 Subject: [PATCH 27/28] changed the print list menue word format --- TodoList/TodoList/List.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TodoList/TodoList/List.m b/TodoList/TodoList/List.m index da3b51a..7ebcdeb 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -93,7 +93,7 @@ -(NSString *)description -(void)printMenu { - [Manager printString:[NSString stringWithFormat:@"Submenu for %@ list. Choose form the following:", self.title]]; + [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"]; From a8fc235621fff9aff169406517e0ac0de1c076ff Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Wed, 1 Jul 2015 19:48:36 -0400 Subject: [PATCH 28/28] added the done property --- TodoList/TodoList/Item.h | 3 ++- TodoList/TodoList/Item.m | 10 ++++++++-- TodoList/TodoList/List.m | 12 ++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/TodoList/TodoList/Item.h b/TodoList/TodoList/Item.h index 1355d19..a29dbc2 100644 --- a/TodoList/TodoList/Item.h +++ b/TodoList/TodoList/Item.h @@ -12,7 +12,8 @@ @property (nonatomic) NSString *content; @property (nonatomic) int priority; +@property (nonatomic) BOOL done; -- (instancetype)initWithContent:(NSString *)content priority:(int)priority; +- (instancetype)initWithContent:(NSString *)content priority:(int)priority ; @end diff --git a/TodoList/TodoList/Item.m b/TodoList/TodoList/Item.m index 3b8cc79..a6e0c68 100644 --- a/TodoList/TodoList/Item.m +++ b/TodoList/TodoList/Item.m @@ -10,19 +10,25 @@ @implementation Item -- (instancetype)initWithContent:(NSString *)content priority:(int)priority +- (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 { - return [NSString stringWithFormat:@"(Priority %@) %@", @(self.priority), self.content]; + 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.m b/TodoList/TodoList/List.m index 7ebcdeb..d5feb0e 100644 --- a/TodoList/TodoList/List.m +++ b/TodoList/TodoList/List.m @@ -74,6 +74,14 @@ -(void)editItem { } +-(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]; @@ -98,6 +106,7 @@ -(void)printMenu { [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"]; } @@ -121,6 +130,9 @@ -(void)showMenu { else if (input == 4) { [self editItem]; } + else if (input == 5) { + [self markDone]; + } else if (input == 99) { break; }