Skip to content
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
Binary file added .DS_Store
Binary file not shown.
Binary file added MarsWater/.DS_Store
Binary file not shown.
247 changes: 132 additions & 115 deletions MarsWater/MarsWater.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file added MarsWater/MarsWater/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions MarsWater/MarsWater/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// AppDelegate.h
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
// Created by Eric Sze on 10/4/15.
// Copyright © 2015 myApps. All rights reserved.
//

#import <UIKit/UIKit.h>
Expand Down
6 changes: 3 additions & 3 deletions MarsWater/MarsWater/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// AppDelegate.m
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
// Created by Eric Sze on 10/4/15.
// Copyright © 2015 myApps. All rights reserved.
//

#import "AppDelegate.h"
Expand Down Expand Up @@ -51,7 +51,7 @@ - (void)applicationWillTerminate:(UIApplication *)application {
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;

- (NSURL *)applicationDocumentsDirectory {
// The directory the application uses to store the Core Data store file. This code uses a directory named "com.mikekavouras.MarsWater" in the application's documents directory.
// The directory the application uses to store the Core Data store file. This code uses a directory named "com.ericsze.MarsWater" in the application's documents directory.
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}

Expand Down
351 changes: 247 additions & 104 deletions MarsWater/MarsWater/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions MarsWater/MarsWater/List+CoreDataProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// List+CoreDataProperties.h
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
// Created by Eric Sze on 10/4/15.
// Copyright © 2015 myApps. All rights reserved.
//
// Choose "Create NSManagedObject Subclass…" from the Core Data editor menu
// to delete and recreate this implementation file for your updated model.
Expand All @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nullable, nonatomic, retain) NSString *title;
@property (nullable, nonatomic, retain) NSDate *createdAt;
@property (nullable, nonatomic, retain) id color;
@property (nullable, nonatomic, retain) NSArray *task;
@property (nullable, nonatomic, retain) NSOrderedSet *task;

@end

Expand Down
4 changes: 2 additions & 2 deletions MarsWater/MarsWater/List+CoreDataProperties.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// List+CoreDataProperties.m
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
// Created by Eric Sze on 10/4/15.
// Copyright © 2015 myApps. All rights reserved.
//
// Choose "Create NSManagedObject Subclass…" from the Core Data editor menu
// to delete and recreate this implementation file for your updated model.
Expand Down
6 changes: 4 additions & 2 deletions MarsWater/MarsWater/List.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// List.h
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
// Created by Eric Sze on 10/4/15.
// Copyright © 2015 myApps. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@class Task;

NS_ASSUME_NONNULL_BEGIN

@interface List : NSManagedObject
Expand Down
5 changes: 3 additions & 2 deletions MarsWater/MarsWater/List.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// List.m
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
// Created by Eric Sze on 10/4/15.
// Copyright © 2015 myApps. All rights reserved.
//

#import "List.h"
#import "Task.h"

@implementation List

Expand Down
4 changes: 2 additions & 2 deletions MarsWater/MarsWater/ListCreationTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// ListCreationTableViewController.h
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
// Created by Eric Sze on 10/4/15.
// Copyright © 2015 myApps. All rights reserved.
//

#import <UIKit/UIKit.h>
Expand Down
27 changes: 19 additions & 8 deletions MarsWater/MarsWater/ListCreationTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// ListCreationTableViewController.m
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
// Created by Eric Sze on 10/4/15.
// Copyright © 2015 myApps. All rights reserved.
//

#import <CoreData/CoreData.h>
#import "ListCreationTableViewController.h"
#import "List.h"
Expand All @@ -14,7 +13,6 @@
@interface ListCreationTableViewController ()

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

@property (nonatomic) List *list;

@end
Expand All @@ -26,38 +24,51 @@ - (void)viewDidLoad {

[self setupNavigationBar];

// gives us access to this class: AppDelegate
AppDelegate *delegate = [UIApplication sharedApplication].delegate;

// insertNewObject: take the entity you want by listing it as a string // take managedObjectContext from AppDelegate
self.list = [NSEntityDescription insertNewObjectForEntityForName:@"List" inManagedObjectContext:delegate.managedObjectContext];

// NSLog(@"%@", self.list);
}

- (void)setupNavigationBar {
// set the title
// set the left bar to cancel
// set the right button to save

self.navigationItem.title = @"Create new list";

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 {
AppDelegate *delegate = [UIApplication sharedApplication].delegate;

self.list.title = self.titleTextField.text;
self.list.createdAt = [NSDate date];

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


NSLog(@"%@", self.list);

if (self.list.color == nil) {
self.list.color = [UIColor colorWithRed:0.363368 green:0.694405 blue:0.180309 alpha:1];
}

[self dismissViewControllerAnimated:YES completion:nil];
}

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

}

@end
4 changes: 2 additions & 2 deletions MarsWater/MarsWater/ListsTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// ListsTableViewController.h
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
// Created by Eric Sze on 10/4/15.
// Copyright © 2015 myApps. All rights reserved.
//

#import <UIKit/UIKit.h>
Expand Down
61 changes: 46 additions & 15 deletions MarsWater/MarsWater/ListsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// ListsTableViewController.m
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
// Created by Eric Sze on 10/4/15.
// Copyright © 2015 myApps. All rights reserved.
//

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

@interface ListsTableViewController () <NSFetchedResultsControllerDelegate>

Expand All @@ -22,30 +22,33 @@ @implementation ListsTableViewController
- (void)viewDidLoad {
[super viewDidLoad];


AppDelegate *delegate = [UIApplication sharedApplication].delegate;

// 1) create an instance of NSFetchRequest with an entity name
// Steps to create a fetch request:
// 1) Create an instance of NSFetchRequest with the entity name in .xcdatamodeld
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"List"];


// 2) create a sort descriptor
// 2) Specify criteria for filtering which objects to fetch Create a sort descriptor
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"createdAt" ascending:NO];

// 3) set the sortDescriptors on the fetchRequest
// 3) Specify how the fetched objects should be sorted // Set the sortDescriptors on the fetchRequest
fetchRequest.sortDescriptors = @[sort];

// 4) create a fetchedResultsController with a fetchRequest and a managedObjectContext,
// 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;

// 5) Perform the fetch
[self.fetchedResultsController performFetch:nil];

// after you fetch, you want to reload the data
[self.tableView reloadData];

}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
Expand All @@ -56,21 +59,49 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
return self.fetchedResultsController.fetchedObjects.count;
}


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

List *list = self.fetchedResultsController.fetchedObjects[indexPath.row];
cell.backgroundColor = (UIColor *)list.color;
cell.textLabel.text = list.title;
cell.detailTextLabel.text = [list.createdAt description];

cell.backgroundColor = (UIColor *)list.color;

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:@"tasksDetailSegue"]) {
NSIndexPath *indexPath = self.tableView.indexPathForSelectedRow;

TasksDetailTableViewController *tasksDetailTVC = segue.destinationViewController;

tasksDetailTVC.list = self.fetchedResultsController.fetchedObjects[indexPath.row];
}
}


// Delete cells from UITableView
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// takes entire dictionary
List *list = self.fetchedResultsController.fetchedObjects[indexPath.row];
// set the delegate
AppDelegate *delegate = [UIApplication sharedApplication].delegate;
[delegate.managedObjectContext deleteObject:list];
[delegate.managedObjectContext save:nil];
}
}

@end

@end
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
<attribute name="dueAt" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="priority" optional="YES" attributeType="Integer 64" defaultValueString="0" syncable="YES"/>
<attribute name="taskDescription" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="updatedAt" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="updateAt" optional="YES" attributeType="Date" syncable="YES"/>
<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="List" positionX="-468" positionY="32" width="128" height="103"/>
<element name="Task" positionX="-668" positionY="-13" width="128" height="148"/>
</elements>
</model>
8 changes: 4 additions & 4 deletions MarsWater/MarsWater/Task+CoreDataProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Task+CoreDataProperties.h
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
// Created by Eric Sze on 10/4/15.
// Copyright © 2015 myApps. All rights reserved.
//
// Choose "Create NSManagedObject Subclass…" from the Core Data editor menu
// to delete and recreate this implementation file for your updated model.
Expand All @@ -18,10 +18,10 @@ NS_ASSUME_NONNULL_BEGIN
@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) NSDate *updateAt;
@property (nullable, nonatomic, retain) NSNumber *priority;
@property (nullable, nonatomic, retain) NSDate *completedAt;
@property (nullable, nonatomic, retain) List *list;
@property (nullable, nonatomic, retain) NSManagedObject *list;

@end

Expand Down
6 changes: 3 additions & 3 deletions MarsWater/MarsWater/Task+CoreDataProperties.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Task+CoreDataProperties.m
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
// Created by Eric Sze on 10/4/15.
// Copyright © 2015 myApps. All rights reserved.
//
// Choose "Create NSManagedObject Subclass…" from the Core Data editor menu
// to delete and recreate this implementation file for your updated model.
Expand All @@ -16,7 +16,7 @@ @implementation Task (CoreDataProperties)
@dynamic taskDescription;
@dynamic createdAt;
@dynamic dueAt;
@dynamic updatedAt;
@dynamic updateAt;
@dynamic priority;
@dynamic completedAt;
@dynamic list;
Expand Down
6 changes: 2 additions & 4 deletions MarsWater/MarsWater/Task.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
// Task.h
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
// Created by Eric Sze on 10/4/15.
// Copyright © 2015 myApps. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@class List;

NS_ASSUME_NONNULL_BEGIN

@interface Task : NSManagedObject
Expand Down
Loading