Skip to content
19 changes: 19 additions & 0 deletions TodoList/TodoList.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand All @@ -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 = "<group>"; };
00824B7B1B42093C0025BB5F /* List.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = List.m; sourceTree = "<group>"; };
00824B7D1B4209E80025BB5F /* Manager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Manager.m; sourceTree = "<group>"; };
00824B801B420FEC0025BB5F /* Item.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Item.h; sourceTree = "<group>"; };
00824B811B4210410025BB5F /* List.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = List.h; sourceTree = "<group>"; };
00824B821B42108A0025BB5F /* Manager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Manager.h; sourceTree = "<group>"; };
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 = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -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 = "<group>";
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -235,6 +253,7 @@
8D9789FC1B3C9A7F007CF4CF /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
19 changes: 19 additions & 0 deletions TodoList/TodoList/Item.h
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions TodoList/TodoList/Item.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Item.m
// TodoList
//
// Created by Felicia Weathers on 6/29/15.
// Copyright (c) 2015 Mike Kavouras. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Item.h"

@implementation Item

-(NSString *)description
{
return self.content;
}

@end
23 changes: 23 additions & 0 deletions TodoList/TodoList/List.h
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions TodoList/TodoList/List.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// List.m
// TodoList
//
// Created by Felicia Weathers on 6/29/15.
// Copyright (c) 2015 Mike Kavouras. All rights reserved.
//

#import <Foundation/Foundation.h>
#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
20 changes: 20 additions & 0 deletions TodoList/TodoList/Manager.h
Original file line number Diff line number Diff line change
@@ -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
142 changes: 142 additions & 0 deletions TodoList/TodoList/Manager.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
//
// Manager.m
// TodoList
//
// Created by Felicia Weathers on 6/29/15.
// Copyright (c) 2015 Mike Kavouras. All rights reserved.
//

#import <Foundation/Foundation.h>
#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
10 changes: 8 additions & 2 deletions TodoList/TodoList/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@

#import <Foundation/Foundation.h>

#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;
}