Skip to content

Unit_2_HW_3_Submission_Ayuna_Vogel #10

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 9 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
Binary file added .DS_Store
Binary file not shown.
22 changes: 0 additions & 22 deletions LICENSE

This file was deleted.

Binary file added MarsWater/.DS_Store
Binary file not shown.
244 changes: 132 additions & 112 deletions MarsWater/MarsWater.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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 Justine Gartner on 10/4/15.
// Copyright © 2015 Justine Gartner. All rights reserved.
//

#import <UIKit/UIKit.h>
Expand Down
14 changes: 11 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 Justine Gartner on 10/4/15.
// Copyright © 2015 Justine Gartner. All rights reserved.
//

#import "AppDelegate.h"
Expand All @@ -12,8 +12,10 @@ @interface AppDelegate ()

@end


@implementation AppDelegate

# pragma mark - AppDelegate methods

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
Expand Down Expand Up @@ -44,14 +46,16 @@ - (void)applicationWillTerminate:(UIApplication *)application {
[self saveContext];
}


#pragma mark - Core Data stack

@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@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 (usually SQLite file). This code uses a directory named "nyc.c4q.justinekay.MarsWater" in the application's documents directory.
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}

Expand All @@ -75,9 +79,12 @@ - (NSPersistentStoreCoordinator *)persistentStoreCoordinator {

_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"MarsWater.sqlite"];

NSError *error = nil;
NSString *failureReason = @"There was an error creating or loading the application's saved data.";

if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {

// Report any error we got.
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[NSLocalizedDescriptionKey] = @"Failed to initialize the application's saved data";
Expand Down Expand Up @@ -124,4 +131,5 @@ - (void)saveContext {
}
}


@end
388 changes: 274 additions & 114 deletions MarsWater/MarsWater/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions MarsWater/MarsWater/CreateListTableViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// ListCreationTableViewController.h
// MarsWater
//
// Created by Justine Gartner on 10/4/15.
// Copyright © 2015 Justine Gartner. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface CreateListTableViewController : UITableViewController

@end
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,74 @@
// ListCreationTableViewController.m
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
// Created by Justine Gartner on 10/4/15.
// Copyright © 2015 Justine Gartner. All rights reserved.
//

#import <CoreData/CoreData.h>
#import "ListCreationTableViewController.h"

#import "CreateListTableViewController.h"
#import "List.h"
#import "AppDelegate.h"

@interface ListCreationTableViewController ()
@interface CreateListTableViewController ()

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

@property (nonatomic) List *list;
@property (nonatomic)List *list;

@end

@implementation ListCreationTableViewController
@implementation CreateListTableViewController

- (void)viewDidLoad {
-(void)viewDidLoad{
[super viewDidLoad];

[self setupNavigationBar];

AppDelegate *delegate = [UIApplication sharedApplication].delegate;

self.list = [NSEntityDescription insertNewObjectForEntityForName:@"List" inManagedObjectContext:delegate.managedObjectContext];


[self setupNavigationBar];
}

- (void)setupNavigationBar {
-(void)setupNavigationBar{

self.navigationItem.title = @"Create new list";
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
self.navigationItem.leftBarButtonItem.tintColor = [UIColor grayColor];
self.navigationItem.rightBarButtonItem.tintColor = [UIColor colorWithRed:224.0/255.0 green:35.0/255.0 blue:70.0/255.0 alpha:1.0];

}

- (void)cancel {
-(void)cancel{

[self dismissViewControllerAnimated:YES completion:nil];
}

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

self.list.color = sender.backgroundColor;
sender.alpha = 0.3;
}

-(void)save{

AppDelegate *delegate = [UIApplication sharedApplication].delegate;

// set task's properties

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

AppDelegate *delegate = [UIApplication sharedApplication].delegate;
[delegate.managedObjectContext save:nil];
[delegate.managedObjectContext save:nil]; // saves task's properties to the core data context, incl. color method that is outside of this method, because appdelegate and entity were initiated in the viewDidLoad method

[self dismissViewControllerAnimated:YES completion:nil];

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

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

@end
16 changes: 16 additions & 0 deletions MarsWater/MarsWater/CreateTaskTableViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// CreateTaskTableViewController.h
// MarsWater
//
// Created by Ayuna Vogel on 10/8/15.
// Copyright © 2015 Justine Gartner. All rights reserved.
//

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

@interface CreateTaskTableViewController : UITableViewController

@property (nonatomic) List *list;

@end
143 changes: 143 additions & 0 deletions MarsWater/MarsWater/CreateTaskTableViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
//
// CreateTaskTableViewController.m
// MarsWater
//
// Created by Ayuna Vogel on 10/8/15.
// Copyright © 2015 Justine Gartner. All rights reserved.
//
#import <CoreData/CoreData.h>

#import "CreateTaskTableViewController.h"
#import "AppDelegate.h"
#import "Task.h"

@interface CreateTaskTableViewController ()

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

@property (nonatomic) Task *task;

@property (nonatomic) NSMutableOrderedSet *tasksInList;


@end

@implementation CreateTaskTableViewController

- (void)viewDidLoad {
[super viewDidLoad];

AppDelegate *delegate = [UIApplication sharedApplication].delegate;

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

[self setupNavigationBar];

self.tasksInList = self.list.task.mutableCopy;


// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}

-(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)];

self.navigationItem.leftBarButtonItem.tintColor = [UIColor grayColor];
self.navigationItem.rightBarButtonItem.tintColor = [UIColor colorWithRed:224.0/255.0 green:35.0/255.0 blue:70.0/255.0 alpha:1.0];

}

-(void)cancel{

[self dismissViewControllerAnimated:YES completion:nil];
}

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

self.task.color = sender.backgroundColor;
sender.alpha = 0.3;
}


-(void)save{

AppDelegate *delegate = [UIApplication sharedApplication].delegate;

self.task.taskDescription = self.titleTextField.text;

if (self.task.createdAt == nil) {

self.task.createdAt = [NSDate date];

}else {

self.task.updatedAt = [NSDate date];
}


self.task.list = self.list;

[delegate.managedObjectContext save:nil]; // nil = No Error, Save with no NSError parameter

[self dismissViewControllerAnimated:YES completion:nil];

NSLog(@"%@", self.task);
}




/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end
4 changes: 2 additions & 2 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 Justine Gartner on 10/4/15.
// Copyright © 2015 Justine Gartner. 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
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 Justine Gartner on 10/4/15.
// Copyright © 2015 Justine Gartner. 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
Loading