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
12 changes: 12 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 */
693956881BC95BD2007CFBD3 /* List+CoreDataProperties.m in Sources */ = {isa = PBXBuildFile; fileRef = 693956851BC95BD2007CFBD3 /* List+CoreDataProperties.m */; settings = {ASSET_TAGS = (); }; };
693956891BC95BD2007CFBD3 /* Task+CoreDataProperties.m in Sources */ = {isa = PBXBuildFile; fileRef = 693956871BC95BD2007CFBD3 /* Task+CoreDataProperties.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 */
693956841BC95BD2007CFBD3 /* List+CoreDataProperties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "List+CoreDataProperties.h"; sourceTree = "<group>"; };
693956851BC95BD2007CFBD3 /* List+CoreDataProperties.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "List+CoreDataProperties.m"; sourceTree = "<group>"; };
693956861BC95BD2007CFBD3 /* Task+CoreDataProperties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Task+CoreDataProperties.h"; sourceTree = "<group>"; };
693956871BC95BD2007CFBD3 /* Task+CoreDataProperties.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "Task+CoreDataProperties.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 @@ -78,6 +84,10 @@
8DA86CD11BC1B329006C50BC /* Model */,
8DA86CAA1BC1AE57006C50BC /* AppDelegate.h */,
8DA86CAB1BC1AE57006C50BC /* AppDelegate.m */,
693956841BC95BD2007CFBD3 /* List+CoreDataProperties.h */,
693956851BC95BD2007CFBD3 /* List+CoreDataProperties.m */,
693956861BC95BD2007CFBD3 /* Task+CoreDataProperties.h */,
693956871BC95BD2007CFBD3 /* Task+CoreDataProperties.m */,
8DA86CD21BC1B8E4006C50BC /* ListsTableViewController.h */,
8DA86CD31BC1B8E4006C50BC /* ListsTableViewController.m */,
8DA86CD51BC1B904006C50BC /* ListCreationTableViewController.h */,
Expand Down Expand Up @@ -188,6 +198,8 @@
8DA86CB51BC1AE57006C50BC /* MarsWater.xcdatamodeld in Sources */,
8DA86CAC1BC1AE57006C50BC /* AppDelegate.m in Sources */,
8DB2F6EA1BC1E75500E58E65 /* Task+CoreDataProperties.m in Sources */,
693956891BC95BD2007CFBD3 /* Task+CoreDataProperties.m in Sources */,
693956881BC95BD2007CFBD3 /* List+CoreDataProperties.m in Sources */,
8DA86CD41BC1B8E4006C50BC /* ListsTableViewController.m in Sources */,
8DB2F6E71BC1E75500E58E65 /* List.m in Sources */,
8DB2F6E91BC1E75500E58E65 /* Task.m in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions MarsWater/MarsWater/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8191" systemVersion="15A284" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand Down
222 changes: 127 additions & 95 deletions MarsWater/MarsWater/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

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

#import "List.h"
#import "Task+CoreDataProperties.h"

NS_ASSUME_NONNULL_BEGIN

@interface List (CoreDataProperties)

@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) NSDate *createdAt;
@property (nullable, nonatomic, retain) NSString *title;
@property (nullable, nonatomic, retain) NSOrderedSet<Task *> *task;

@end

@interface List (CoreDataGeneratedAccessors)

- (void)insertObject:(Task *)value inTaskAtIndex:(NSUInteger)idx;
- (void)removeObjectFromTaskAtIndex:(NSUInteger)idx;
- (void)insertTask:(NSArray<Task *> *)value atIndexes:(NSIndexSet *)indexes;
- (void)removeTaskAtIndexes:(NSIndexSet *)indexes;
- (void)replaceObjectInTaskAtIndex:(NSUInteger)idx withObject:(Task *)value;
- (void)replaceTaskAtIndexes:(NSIndexSet *)indexes withTask:(NSArray<Task *> *)values;
- (void)addTaskObject:(Task *)value;
- (void)removeTaskObject:(Task *)value;
- (void)addTask:(NSOrderedSet<Task *> *)values;
- (void)removeTask:(NSOrderedSet<Task *> *)values;

@end

Expand Down
6 changes: 3 additions & 3 deletions MarsWater/MarsWater/List+CoreDataProperties.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// List+CoreDataProperties.m
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Created by Z on 10/10/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
//
// Choose "Create NSManagedObject Subclass…" from the Core Data editor menu
Expand All @@ -13,9 +13,9 @@

@implementation List (CoreDataProperties)

@dynamic title;
@dynamic createdAt;
@dynamic color;
@dynamic createdAt;
@dynamic title;
@dynamic task;

@end
36 changes: 28 additions & 8 deletions MarsWater/MarsWater/ListCreationTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
#import "List.h"
#import "AppDelegate.h"

@interface ListCreationTableViewController ()

@property (weak, nonatomic) IBOutlet UITextField *titleTextField;
@interface ListCreationTableViewController () <UITextFieldDelegate>
@property (nonatomic) NSMutableOrderedSet *myTasks;
@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet UITextField *taskField;

@property (nonatomic) List *list;

Expand All @@ -39,25 +40,44 @@ - (void)setupNavigationBar {

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.list.title = self.titleTextField.text;
AppDelegate *delegate= [UIApplication sharedApplication].delegate;
if ([self.textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length==0) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Save Failed" message:@"Set a name" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
return;
}
else if([self.taskField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length!=0) {
Task *task = [NSEntityDescription insertNewObjectForEntityForName:@"Task" inManagedObjectContext:delegate.managedObjectContext];
[task setValue:self.taskField.text forKey:@"taskDescription"];
self.taskField.text = @"";
[self.myTasks addObject:task];
}

[self.list setValue:self.textField.text forKey:@"title"];

self.list.createdAt = [NSDate date];

AppDelegate *delegate = [UIApplication sharedApplication].delegate;
[delegate.managedObjectContext save:nil];
[self.list setValue:self.myTasks forKey:@"task"];

[self dismissViewControllerAnimated:YES completion:nil];
[delegate.managedObjectContext save:nil];
[self cancel];
}

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

#pragma mark - Text Field methods
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[self.view endEditing:YES];
return YES;
}

@end
34 changes: 31 additions & 3 deletions MarsWater/MarsWater/ListsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,30 @@ @interface ListsTableViewController () <NSFetchedResultsControllerDelegate>

@implementation ListsTableViewController


#pragma mark - lifecycle methods

- (void)viewWillAppear:(BOOL)animated{

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]initWithEntityName:@"List"];
fetchRequest.sortDescriptors = @[[[NSSortDescriptor alloc] initWithKey:@"createdAt" ascending:NO]];
AppDelegate *delegate = [UIApplication sharedApplication].delegate;

self.fetchedResultsController = [[NSFetchedResultsController alloc]initWithFetchRequest:fetchRequest managedObjectContext:delegate.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
self.fetchedResultsController.delegate = self;
[self.fetchedResultsController performFetch:nil];

[self.tableView reloadData];
}

- (void)viewDidLoad {
[super viewDidLoad];


AppDelegate *delegate = [UIApplication sharedApplication].delegate;

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


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

Expand All @@ -45,7 +59,6 @@ - (void)viewDidLoad {
[self.tableView reloadData];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
Expand All @@ -67,6 +80,21 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}

#pragma mark - delete methods

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

if (editingStyle == UITableViewCellEditingStyleDelete) {
List *listRemoved = self.fetchedResultsController.fetchedObjects[indexPath.row];
AppDelegate *delegate = [UIApplication sharedApplication].delegate;
[delegate.managedObjectContext deleteObject:listRemoved];
[self viewWillAppear:YES];
}
}

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

[self.tableView reloadData];
Expand Down
8 changes: 4 additions & 4 deletions MarsWater/MarsWater/Task+CoreDataProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Task+CoreDataProperties.h
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Created by Z on 10/10/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
//
// Choose "Create NSManagedObject Subclass…" from the Core Data editor menu
Expand All @@ -15,12 +15,12 @@ NS_ASSUME_NONNULL_BEGIN

@interface Task (CoreDataProperties)

@property (nullable, nonatomic, retain) NSString *taskDescription;
@property (nullable, nonatomic, retain) NSDate *completedAt;
@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) NSString *taskDescription;
@property (nullable, nonatomic, retain) NSDate *updatedAt;
@property (nullable, nonatomic, retain) List *list;

@end
Expand Down
8 changes: 4 additions & 4 deletions MarsWater/MarsWater/Task+CoreDataProperties.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Task+CoreDataProperties.m
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Created by Z on 10/10/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
//
// Choose "Create NSManagedObject Subclass…" from the Core Data editor menu
Expand All @@ -13,12 +13,12 @@

@implementation Task (CoreDataProperties)

@dynamic taskDescription;
@dynamic completedAt;
@dynamic createdAt;
@dynamic dueAt;
@dynamic updatedAt;
@dynamic priority;
@dynamic completedAt;
@dynamic taskDescription;
@dynamic updatedAt;
@dynamic list;

@end