Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b72236f
Hey, I made a change.
NataliaEstrella Jun 27, 2015
9d7db5a
I changed something
qwang216 Jun 27, 2015
dc75a31
added something else
NataliaEstrella Jun 27, 2015
65cccd5
added interface and implementation
qwang216 Jun 27, 2015
82485d1
added property
qwang216 Jun 27, 2015
c68af53
changed
NataliaEstrella Jun 27, 2015
2028032
changed something
NataliaEstrella Jun 27, 2015
9100050
new
qwang216 Jun 27, 2015
44bf306
Made changes to interface and priority.
NataliaEstrella Jun 28, 2015
6163bf4
Arrays with Cameron
NataliaEstrella Jun 28, 2015
7504395
small changes
NataliaEstrella Jun 28, 2015
7607470
bool
qwang216 Jun 28, 2015
6c49738
this might work
qwang216 Jun 28, 2015
d0dd201
improved user input
qwang216 Jun 28, 2015
87049bf
changed something
qwang216 Jun 28, 2015
776cf58
another change
qwang216 Jun 28, 2015
a2bbd9a
updated the user input loop
qwang216 Jun 28, 2015
ed0bccc
Hey, this looks like a solid start :)
NataliaEstrella Jun 30, 2015
ed5e1f5
added three class in different files
qwang216 Jun 30, 2015
89982e4
Creating list and items are functional
NataliaEstrella Jun 30, 2015
fb5a306
Merge remote-tracking branch 'origin/master'
NataliaEstrella Jun 30, 2015
e9eb2ab
Implement the classes in separate files
NataliaEstrella Jun 30, 2015
6217046
Remove item implementation in progress
NataliaEstrella Jun 30, 2015
909a50c
Edit feature completed :)
NataliaEstrella Jul 1, 2015
c9ef55b
Made priority check. Also, learned about recursion!
NataliaEstrella Jul 1, 2015
3d0a1b2
Added title to lists
NataliaEstrella Jul 1, 2015
53743e3
Changed list title
NataliaEstrella Jul 1, 2015
b9adaef
changed the print list menue word format
qwang216 Jul 1, 2015
a8fc235
added the done property
qwang216 Jul 1, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions TodoList/TodoList.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 = "<group>"; };
D4F83A8C1B425B8A005D40B4 /* Item.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Item.h; sourceTree = "<group>"; };
D4F83A8D1B425B8A005D40B4 /* Item.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Item.m; sourceTree = "<group>"; };
D4F83A8F1B425B98005D40B4 /* List.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = List.h; sourceTree = "<group>"; };
D4F83A901B425B98005D40B4 /* List.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = List.m; sourceTree = "<group>"; };
D4F83A921B425BA3005D40B4 /* Manager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Manager.h; sourceTree = "<group>"; };
D4F83A931B425BA3005D40B4 /* Manager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Manager.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -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 = "<group>";
Expand Down Expand Up @@ -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;
};
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 Jason Wang on 6/30/15.
// Copyright (c) 2015 Mike Kavouras. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Item : NSObject

@property (nonatomic) NSString *content;
@property (nonatomic) int priority;
@property (nonatomic) BOOL done;

- (instancetype)initWithContent:(NSString *)content priority:(int)priority ;

@end
34 changes: 34 additions & 0 deletions TodoList/TodoList/Item.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Item.m
// TodoList
//
// Created by Jason Wang on 6/30/15.
// Copyright (c) 2015 Mike Kavouras. All rights reserved.
//

#import "Item.h"

@implementation Item

- (instancetype)initWithContent:(NSString *)content priority:(int)priority
{
self = [super init];
if (self) {
self.content = content;
self.priority = priority;
self.done = NO;
}
return self;
}

-(NSString *)description
{
if (self.done) {
return [NSString stringWithFormat:@"(Priority %@) [X] %@ ", @(self.priority), self.content];
} else {
return [NSString stringWithFormat:@"(Priority %@) [ ] %@ ", @(self.priority), self.content];
}

}

@end
21 changes: 21 additions & 0 deletions TodoList/TodoList/List.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// List.h
// TodoList
//
// Created by Jason Wang on 6/30/15.
// Copyright (c) 2015 Mike Kavouras. All rights reserved.
//

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

@interface List : NSObject

@property (nonatomic) NSMutableArray *items;
@property (nonatomic) NSString *title;
@property (nonatomic) int priority;

-(void)showMenu;


@end
142 changes: 142 additions & 0 deletions TodoList/TodoList/List.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
//
// List.m
// TodoList
//
// Created by Jason Wang on 6/30/15.
// Copyright (c) 2015 Mike Kavouras. All rights reserved.
//

#import "List.h"
#import "Manager.h"

@implementation List

- (instancetype)init
{
self = [super init];
if (self) {
self.items = [[NSMutableArray alloc] init];
}
return self;
}

-(int)getPriority {
[Manager printString:@"Enter priority (1 - 4):"];
int priority = [Manager getInputString].intValue;
if (priority < 1 || priority > 4) {
[Manager printString:@"Outside limits! 1 is min, 4 is max."];
//instead of making the worlds saddest loop; recursion
// while (priority < 1 || priority > 4) {
// [Manager printString:@"Enter priority (1 - 4):"];
// priority = [Manager getInputString].intValue;
// }
return [self getPriority];
}
return priority;
}

-(Item *)addItem {
[Manager printString:@"Enter task:"];
NSString *task = [Manager getInputString];

int priority = [self getPriority];

Item *newItem = [[Item alloc] initWithContent:task priority:priority];
[self.items addObject:newItem];

[self printList];
return newItem;

}

-(void)removeItem {
[self printList];
[Manager printString:@"Choose the index to remove:"];
int removeIndex = [Manager getInputString].intValue-1;
[self.items removeObjectAtIndex:removeIndex];
[self printList];
}

-(void)editItem {
[self printList];
[Manager printString:@"Choose the index to edit:"];
int editIndex = [Manager getInputString].intValue-1;
Item *item = [self.items objectAtIndex:editIndex];

[Manager printString:@"Enter task:"];
NSString *task = [Manager getInputString];

int priority = [self getPriority];

item.content = task;
item.priority = priority;
[self printList];

}

-(void)markDone {
[self printList];
[Manager printString:@"Chose the index to Mark Done:"];
int markIndex = [Manager getInputString].intValue-1;
Item *markItem = [self.items objectAtIndex:markIndex];
markItem.done = YES;
}

-(void)printList {
[Manager printString:[NSString stringWithFormat:@"Title: %@", self.title]];
[Manager printString:self.description];
}


-(NSString *)description
{
NSMutableString *desc = [[NSMutableString alloc] init];
[desc appendString:@"\n"];
for (int i = 0; i < self.items.count; i++) {
NSString *newLine = [NSString stringWithFormat:@"%@: %@\n",@(i+1), self.items[i]];
[desc appendString:newLine];
}
return desc;
}


-(void)printMenu {
[Manager printString:[NSString stringWithFormat:@"\n\n~[%@]~\n \nChoose form the following:", self.title]];
[Manager printString:@"1. Print list"];
[Manager printString:@"2. Add Item"];
[Manager printString:@"3. Remove Item"];
[Manager printString:@"4. Edit Item"];
[Manager printString:@"5. Mark Done"];
[Manager printString:@"99. Main menu"];
}

-(int)getMenuInput {
[self printMenu];
return [Manager getInputString].intValue;
}

-(void)showMenu {
while (true) {
int input = [self getMenuInput];
if (input == 1) {
[self printList];
}
else if (input == 2) {
[self addItem];
}
else if (input == 3) {
[self removeItem];
}
else if (input == 4) {
[self editItem];
}
else if (input == 5) {
[self markDone];
}
else if (input == 99) {
break;
}
}
}

@end
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 Jason Wang on 6/30/15.
// Copyright (c) 2015 Mike Kavouras. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Manager : NSObject

@property (nonatomic) NSMutableArray *lists;

+(NSString *)getInputString;
+(void)printString:(NSString *)string;

-(void)showMenu;

@end
87 changes: 87 additions & 0 deletions TodoList/TodoList/Manager.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// Manager.m
// TodoList
//
// Created by Jason Wang on 6/30/15.
// Copyright (c) 2015 Mike Kavouras. All rights reserved.
//

#import "Manager.h"
#import "List.h"

@implementation Manager

- (instancetype)init
{
self = [super init];
if (self) {
self.lists = [[NSMutableArray alloc] init];
}
return self;
}

// Gets the input from scanf as an NSString
+(NSString *)getInputString {
int numLength = 1024;
char input[numLength];
fgets(input, numLength, stdin);
fflush(stdin);

// Gets rid of \n at the end of each input
size_t length = strlen(input) - 1;
if (input[length] == '\n')
input[length] = '\0';

return [NSString stringWithUTF8String:input];
}

+(void)printString:(NSString *)string {
printf("%s\n", [string cStringUsingEncoding:NSUTF8StringEncoding]);
}

-(List *)createList {
List *newList = [[List alloc] init];
[Manager printString:@"List name:"];
newList.title = [Manager getInputString];
[self.lists addObject:newList];
return newList;

}

-(void)printMenu {
[Manager printString:@"Main menu. Choose form the following:"];
[Manager printString:@"1. Print all lists"];
[Manager printString:@"2. Create List"];
[Manager printString:@"99. Exit"];
}

-(int)getMenuInput {
[self printMenu];
return [Manager getInputString].intValue;
}

-(void)printLists {
for (List *list in self.lists) {
[Manager printString:list.title];
[Manager printString:list.description];
}
}

-(void)showMenu {
while (true) {
int input = [self getMenuInput];
if (input == 1) {
[self printLists];
}
else if (input == 2) {
List *newList = [self createList];
[newList showMenu];
}
else if (input == 99) {
break;
}
}
}


@end
Loading