Skip to content

Lauren Caponong Unit 2 Homework 3 #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions MarsWater/MarsWater.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
895332B61BC840F800FCAD52 /* TasksTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 895332B51BC840F800FCAD52 /* TasksTableViewController.m */; settings = {ASSET_TAGS = (); }; };
895332B91BC8428600FCAD52 /* TaskCreationTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 895332B81BC8428600FCAD52 /* TaskCreationTableViewController.m */; settings = {ASSET_TAGS = (); }; };
8DA86CA91BC1AE57006C50BC /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DA86CA81BC1AE57006C50BC /* main.m */; };
8DA86CAC1BC1AE57006C50BC /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DA86CAB1BC1AE57006C50BC /* AppDelegate.m */; };
8DA86CB21BC1AE57006C50BC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8DA86CB01BC1AE57006C50BC /* Main.storyboard */; };
Expand All @@ -22,6 +24,10 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
895332B41BC840F800FCAD52 /* TasksTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TasksTableViewController.h; sourceTree = "<group>"; };
895332B51BC840F800FCAD52 /* TasksTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TasksTableViewController.m; sourceTree = "<group>"; };
895332B71BC8428600FCAD52 /* TaskCreationTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TaskCreationTableViewController.h; sourceTree = "<group>"; };
895332B81BC8428600FCAD52 /* TaskCreationTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TaskCreationTableViewController.m; sourceTree = "<group>"; };
8DA86CA41BC1AE57006C50BC /* MarsWater.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MarsWater.app; sourceTree = BUILT_PRODUCTS_DIR; };
8DA86CA81BC1AE57006C50BC /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
8DA86CAA1BC1AE57006C50BC /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -56,6 +62,13 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
89DE602A1BC85BD50029B2B5 /* LISTS VS TASKS */ = {
isa = PBXGroup;
children = (
);
name = "LISTS VS TASKS";
sourceTree = "<group>";
};
8DA86C9B1BC1AE57006C50BC = {
isa = PBXGroup;
children = (
Expand All @@ -78,6 +91,11 @@
8DA86CD11BC1B329006C50BC /* Model */,
8DA86CAA1BC1AE57006C50BC /* AppDelegate.h */,
8DA86CAB1BC1AE57006C50BC /* AppDelegate.m */,
895332B41BC840F800FCAD52 /* TasksTableViewController.h */,
895332B51BC840F800FCAD52 /* TasksTableViewController.m */,
895332B71BC8428600FCAD52 /* TaskCreationTableViewController.h */,
895332B81BC8428600FCAD52 /* TaskCreationTableViewController.m */,
89DE602A1BC85BD50029B2B5 /* LISTS VS TASKS */,
8DA86CD21BC1B8E4006C50BC /* ListsTableViewController.h */,
8DA86CD31BC1B8E4006C50BC /* ListsTableViewController.m */,
8DA86CD51BC1B904006C50BC /* ListCreationTableViewController.h */,
Expand Down Expand Up @@ -187,10 +205,12 @@
files = (
8DA86CB51BC1AE57006C50BC /* MarsWater.xcdatamodeld in Sources */,
8DA86CAC1BC1AE57006C50BC /* AppDelegate.m in Sources */,
895332B91BC8428600FCAD52 /* TaskCreationTableViewController.m in Sources */,
8DB2F6EA1BC1E75500E58E65 /* Task+CoreDataProperties.m in Sources */,
8DA86CD41BC1B8E4006C50BC /* ListsTableViewController.m in Sources */,
8DB2F6E71BC1E75500E58E65 /* List.m in Sources */,
8DB2F6E91BC1E75500E58E65 /* Task.m in Sources */,
895332B61BC840F800FCAD52 /* TasksTableViewController.m in Sources */,
8DA86CD71BC1B904006C50BC /* ListCreationTableViewController.m in Sources */,
8DA86CA91BC1AE57006C50BC /* main.m in Sources */,
8DB2F6E81BC1E75500E58E65 /* List+CoreDataProperties.m in Sources */,
Expand Down
169 changes: 155 additions & 14 deletions MarsWater/MarsWater/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions MarsWater/MarsWater/ListCreationTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ - (void)save {
}

- (IBAction)colorButtonTapped:(UIButton *)sender {

self.list.color = sender.backgroundColor;
}







@end
23 changes: 21 additions & 2 deletions MarsWater/MarsWater/ListsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

#import <CoreData/CoreData.h>
#import "ListsTableViewController.h"
#import "TasksTableViewController.h"
#import "AppDelegate.h"
#import "List.h"

@interface ListsTableViewController () <NSFetchedResultsControllerDelegate>
@interface ListsTableViewController () <NSFetchedResultsControllerDelegate, UITableViewDelegate, UITableViewDataSource>

@property (nonatomic) NSFetchedResultsController *fetchedResultsController;

Expand All @@ -20,6 +21,7 @@ @interface ListsTableViewController () <NSFetchedResultsControllerDelegate>
@implementation ListsTableViewController

- (void)viewDidLoad {

[super viewDidLoad];


Expand Down Expand Up @@ -53,6 +55,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return self.fetchedResultsController.fetchedObjects.count;
}

Expand All @@ -65,12 +68,28 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.detailTextLabel.text = [list.createdAt description];

return cell;

}



- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {

[self.tableView reloadData];
}



-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

if ([segue.identifier isEqualToString:@"taskSegue"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

TasksTableViewController *tvcForTasks = segue.destinationViewController;
tvcForTasks.list = self.fetchedResultsController.fetchedObjects[indexPath.row];
}
}


@end

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<relationship name="list" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="List" inverseName="task" inverseEntity="List" syncable="YES"/>
</entity>
<elements>
<element name="Task" positionX="-63" positionY="-18" width="128" height="148"/>
<element name="List" positionX="144" positionY="-18" width="128" height="103"/>
<element name="Task" positionX="-63" positionY="-18" width="128" height="150"/>
</elements>
</model>
1 change: 1 addition & 0 deletions MarsWater/MarsWater/Task+CoreDataProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nullable, nonatomic, retain) NSDate *updatedAt;
@property (nullable, nonatomic, retain) NSNumber *priority;
@property (nullable, nonatomic, retain) NSDate *completedAt;
//@property (nullable, nonatomic, retain) id color;
@property (nullable, nonatomic, retain) List *list;

@end
Expand Down
1 change: 1 addition & 0 deletions MarsWater/MarsWater/Task+CoreDataProperties.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ @implementation Task (CoreDataProperties)
@dynamic priority;
@dynamic completedAt;
@dynamic list;
//@dynamic color;

@end
13 changes: 13 additions & 0 deletions MarsWater/MarsWater/TaskCreationTableViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// TaskCreationTableViewController.h
// MarsWater
//
// Created by Lauren Caponong on 10/9/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface TaskCreationTableViewController : UITableViewController

@end
83 changes: 83 additions & 0 deletions MarsWater/MarsWater/TaskCreationTableViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// TaskCreationTableViewController.m
// MarsWater
//
// Created by Lauren Caponong on 10/9/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
//

#import <CoreData/CoreData.h>
#import "TaskCreationTableViewController.h"
#import "Task.h"
#import "AppDelegate.h"


// TASK PROPERTIES

//@property (nullable, nonatomic, retain) NSString *taskDescription;
//@property (nullable, nonatomic, retain) NSDate *createdAt;
//@property (nullable, nonatomic, retain) NSDate *dueAt;
//@property (nullable, nonatomic, retain) NSDate *updatedAt;
//@property (nullable, nonatomic, retain) NSNumber *priority;
//@property (nullable, nonatomic, retain) NSDate *completedAt;
//@property (nullable, nonatomic, retain) id color;
//@property (nullable, nonatomic, retain) List *list;




@interface TaskCreationTableViewController ()

@property (weak, nonatomic) IBOutlet UITextField *titleTextField;
@property (nonatomic) Task *task;

@end



@implementation TaskCreationTableViewController

- (void)viewDidLoad {
[super viewDidLoad];

[self setupNavigationBar];

AppDelegate *delegate = [UIApplication sharedApplication].delegate;

self.task = [NSEntityDescription insertNewObjectForEntityForName:@"Task" inManagedObjectContext:delegate.managedObjectContext];
}

- (void)setupNavigationBar {

self.navigationItem.title = @"Create New Task";

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel)];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save)];

// set the right button to save
}

- (void)cancel {
[self dismissViewControllerAnimated:YES completion:nil];
}

- (void)save {
self.task.taskDescription = self.titleTextField.text;
self.task.createdAt = [NSDate date];

AppDelegate *delegate = [UIApplication sharedApplication].delegate;
[delegate.managedObjectContext save:nil];

[self dismissViewControllerAnimated:YES completion:nil];
}

//- (IBAction)colorButtonTapped:(UIButton *)sender {
//
// self.task.color = sender.backgroundColor;
//
//}


@end

16 changes: 16 additions & 0 deletions MarsWater/MarsWater/TasksTableViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// TasksTableViewController.h
// MarsWater
//
// Created by Lauren Caponong on 10/9/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "List.h"

@interface TasksTableViewController : UITableViewController

@property (nonatomic) List *list;

@end
84 changes: 84 additions & 0 deletions MarsWater/MarsWater/TasksTableViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//
// TasksTableViewController.m
// MarsWater
//
// Created by Lauren Caponong on 10/9/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
//

#import <CoreData/CoreData.h>
#import "TasksTableViewController.h"
#import "AppDelegate.h"
#import "Task.h"

@interface TasksTableViewController () <NSFetchedResultsControllerDelegate, UITableViewDataSource, UITableViewDelegate>

@property (nonatomic) NSFetchedResultsController *fetchedResultsController;

@end

@implementation TasksTableViewController

- (void)viewDidLoad {
[super viewDidLoad];


AppDelegate *delegate = [UIApplication sharedApplication].delegate;

// 1) create an instance of NSFetchRequest with an entity name
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Task"];


// 2) create a sort descriptor
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"createdAt" ascending:NO];

// 3) set the sortDescriptors on the fetchRequest
fetchRequest.sortDescriptors = @[sort];

// 4) create a fetchedResultsController with a fetchRequest and a managedObjectContext,
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:delegate.managedObjectContext sectionNameKeyPath:nil cacheName:nil];

self.fetchedResultsController.delegate = self;

[self.fetchedResultsController performFetch:nil];

[self.tableView reloadData];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.fetchedResultsController.fetchedObjects.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: @"TaskCellIdentifier" forIndexPath:indexPath];

Task *task = self.fetchedResultsController.fetchedObjects[indexPath.row];

// cell.backgroundColor = (UIColor *)task.color;

cell.textLabel.text = task.taskDescription;

NSString *taskCreatedAtTime = [task.createdAt description];
cell.detailTextLabel.text = taskCreatedAtTime;

return cell;
}



- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {

[self.tableView reloadData];
}




@end