From f4458607e27545abd5f4c3d5202e862048c077a9 Mon Sep 17 00:00:00 2001 From: Bereket Ghebremedhin Date: Fri, 9 Oct 2015 15:51:59 -0400 Subject: [PATCH 01/10] laid out some stuff, figuring out how to add tasks and persist them --- MarsWater/MarsWater.xcodeproj/project.pbxproj | 12 ++ .../MarsWater/Base.lproj/Main.storyboard | 137 +++++++++++++++++- .../ListCreationTableViewController.m | 8 + .../MarsWater/ListsTableViewController.m | 19 +++ .../MarsWater/TaskCreationViewController.h | 15 ++ .../MarsWater/TaskCreationViewController.m | 83 +++++++++++ .../MarsWater/TasksTableViewController.h | 16 ++ .../MarsWater/TasksTableViewController.m | 112 ++++++++++++++ 8 files changed, 399 insertions(+), 3 deletions(-) create mode 100644 MarsWater/MarsWater/TaskCreationViewController.h create mode 100644 MarsWater/MarsWater/TaskCreationViewController.m create mode 100644 MarsWater/MarsWater/TasksTableViewController.h create mode 100644 MarsWater/MarsWater/TasksTableViewController.m diff --git a/MarsWater/MarsWater.xcodeproj/project.pbxproj b/MarsWater/MarsWater.xcodeproj/project.pbxproj index a2f82e3..3f48698 100644 --- a/MarsWater/MarsWater.xcodeproj/project.pbxproj +++ b/MarsWater/MarsWater.xcodeproj/project.pbxproj @@ -19,6 +19,8 @@ 8DB2F6E81BC1E75500E58E65 /* List+CoreDataProperties.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DB2F6E21BC1E75500E58E65 /* List+CoreDataProperties.m */; }; 8DB2F6E91BC1E75500E58E65 /* Task.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DB2F6E41BC1E75500E58E65 /* Task.m */; }; 8DB2F6EA1BC1E75500E58E65 /* Task+CoreDataProperties.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DB2F6E61BC1E75500E58E65 /* Task+CoreDataProperties.m */; }; + ABF463FB1BC5F24C0054CE11 /* TasksTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ABF463FA1BC5F24C0054CE11 /* TasksTableViewController.m */; settings = {ASSET_TAGS = (); }; }; + ABF463FE1BC600E70054CE11 /* TaskCreationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ABF463FD1BC600E70054CE11 /* TaskCreationViewController.m */; settings = {ASSET_TAGS = (); }; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -43,6 +45,10 @@ 8DB2F6E41BC1E75500E58E65 /* Task.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Task.m; sourceTree = ""; }; 8DB2F6E51BC1E75500E58E65 /* Task+CoreDataProperties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Task+CoreDataProperties.h"; sourceTree = ""; }; 8DB2F6E61BC1E75500E58E65 /* Task+CoreDataProperties.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "Task+CoreDataProperties.m"; sourceTree = ""; }; + ABF463F91BC5F24C0054CE11 /* TasksTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TasksTableViewController.h; sourceTree = ""; }; + ABF463FA1BC5F24C0054CE11 /* TasksTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TasksTableViewController.m; sourceTree = ""; }; + ABF463FC1BC600E70054CE11 /* TaskCreationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TaskCreationViewController.h; sourceTree = ""; }; + ABF463FD1BC600E70054CE11 /* TaskCreationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TaskCreationViewController.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -82,6 +88,10 @@ 8DA86CD31BC1B8E4006C50BC /* ListsTableViewController.m */, 8DA86CD51BC1B904006C50BC /* ListCreationTableViewController.h */, 8DA86CD61BC1B904006C50BC /* ListCreationTableViewController.m */, + ABF463F91BC5F24C0054CE11 /* TasksTableViewController.h */, + ABF463FA1BC5F24C0054CE11 /* TasksTableViewController.m */, + ABF463FC1BC600E70054CE11 /* TaskCreationViewController.h */, + ABF463FD1BC600E70054CE11 /* TaskCreationViewController.m */, 8DA86CB01BC1AE57006C50BC /* Main.storyboard */, 8DA86CB61BC1AE57006C50BC /* Assets.xcassets */, 8DA86CB81BC1AE57006C50BC /* LaunchScreen.storyboard */, @@ -189,8 +199,10 @@ 8DA86CAC1BC1AE57006C50BC /* AppDelegate.m in Sources */, 8DB2F6EA1BC1E75500E58E65 /* Task+CoreDataProperties.m in Sources */, 8DA86CD41BC1B8E4006C50BC /* ListsTableViewController.m in Sources */, + ABF463FE1BC600E70054CE11 /* TaskCreationViewController.m in Sources */, 8DB2F6E71BC1E75500E58E65 /* List.m in Sources */, 8DB2F6E91BC1E75500E58E65 /* Task.m in Sources */, + ABF463FB1BC5F24C0054CE11 /* TasksTableViewController.m in Sources */, 8DA86CD71BC1B904006C50BC /* ListCreationTableViewController.m in Sources */, 8DA86CA91BC1AE57006C50BC /* main.m in Sources */, 8DB2F6E81BC1E75500E58E65 /* List+CoreDataProperties.m in Sources */, diff --git a/MarsWater/MarsWater/Base.lproj/Main.storyboard b/MarsWater/MarsWater/Base.lproj/Main.storyboard index 13ead89..9de66b0 100644 --- a/MarsWater/MarsWater/Base.lproj/Main.storyboard +++ b/MarsWater/MarsWater/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -41,6 +41,9 @@ + + + @@ -75,7 +78,7 @@ - + @@ -213,7 +216,99 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -232,5 +327,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MarsWater/MarsWater/ListCreationTableViewController.m b/MarsWater/MarsWater/ListCreationTableViewController.m index 0ecf6e9..4c6a099 100644 --- a/MarsWater/MarsWater/ListCreationTableViewController.m +++ b/MarsWater/MarsWater/ListCreationTableViewController.m @@ -10,6 +10,7 @@ #import "ListCreationTableViewController.h" #import "List.h" #import "AppDelegate.h" +#import "TasksTableViewController.h" @interface ListCreationTableViewController () @@ -60,4 +61,11 @@ - (IBAction)colorButtonTapped:(UIButton *)sender { self.list.color = sender.backgroundColor; } + +//-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ +// +// +// +//} + @end diff --git a/MarsWater/MarsWater/ListsTableViewController.m b/MarsWater/MarsWater/ListsTableViewController.m index 8a2659c..3994fd8 100644 --- a/MarsWater/MarsWater/ListsTableViewController.m +++ b/MarsWater/MarsWater/ListsTableViewController.m @@ -10,6 +10,8 @@ #import "ListsTableViewController.h" #import "AppDelegate.h" #import "List.h" +#import "TasksTableViewController.h" +#import "ListCreationTableViewController.h" @interface ListsTableViewController () @@ -72,5 +74,22 @@ - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id) [self.tableView reloadData]; } + +-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ + + + if([segue.identifier isEqual: @"TasksSegueIdentifer"]){ + + + UINavigationController* navigationController = segue.destinationViewController; + + TasksTableViewController* tableViewController = navigationController.childViewControllers[0]; + NSIndexPath* indexPath = [self.tableView indexPathForSelectedRow]; + tableViewController.list = self.fetchedResultsController.fetchedObjects[indexPath.row]; + } + +} + + @end diff --git a/MarsWater/MarsWater/TaskCreationViewController.h b/MarsWater/MarsWater/TaskCreationViewController.h new file mode 100644 index 0000000..50a3f16 --- /dev/null +++ b/MarsWater/MarsWater/TaskCreationViewController.h @@ -0,0 +1,15 @@ +// +// TaskCreationViewController.h +// MarsWater +// +// Created by Bereket on 10/7/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import + +@interface TaskCreationViewController : UIViewController + + + +@end diff --git a/MarsWater/MarsWater/TaskCreationViewController.m b/MarsWater/MarsWater/TaskCreationViewController.m new file mode 100644 index 0000000..ef3a056 --- /dev/null +++ b/MarsWater/MarsWater/TaskCreationViewController.m @@ -0,0 +1,83 @@ +// +// TaskCreationViewController.m +// MarsWater +// +// Created by Bereket on 10/7/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import "TaskCreationViewController.h" + +@interface TaskCreationViewController () + +@end + +@implementation TaskCreationViewController + +- (IBAction)AddTaskButtonTapped:(id)sender { + + + + +} + + + + +- (void)viewDidLoad { + [super viewDidLoad]; + + [self setupNavigationBar]; + // Do any additional setup after loading the view. +} + + + +- (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 dismissViewControllerAnimated:YES completion:nil]; +// self.list.title = self.titleTextField.text; +// self.list.createdAt = [NSDate date]; +// +// AppDelegate *delegate = [UIApplication sharedApplication].delegate; +// [delegate.managedObjectContext save:nil]; +// +// [self dismissViewControllerAnimated:YES completion:nil]; +} + + + + + + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +/* +#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 diff --git a/MarsWater/MarsWater/TasksTableViewController.h b/MarsWater/MarsWater/TasksTableViewController.h new file mode 100644 index 0000000..fb63e39 --- /dev/null +++ b/MarsWater/MarsWater/TasksTableViewController.h @@ -0,0 +1,16 @@ +// +// TasksTableViewController.h +// MarsWater +// +// Created by Bereket on 10/7/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import +#import "List.h" + +@interface TasksTableViewController : UITableViewController + +@property (nonatomic) List* list; + +@end diff --git a/MarsWater/MarsWater/TasksTableViewController.m b/MarsWater/MarsWater/TasksTableViewController.m new file mode 100644 index 0000000..ec4c661 --- /dev/null +++ b/MarsWater/MarsWater/TasksTableViewController.m @@ -0,0 +1,112 @@ +// +// TasksTableViewController.m +// MarsWater +// +// Created by Bereket on 10/7/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import "TasksTableViewController.h" + +@interface TasksTableViewController () + +@end + +@implementation TasksTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + [self setupNavigationBar]; + NSLog(@"%@", self.list.title); + + // Uncomment the following line to preserve selection between presentations. + // self.clearsSelectionOnViewWillAppear = NO; + + // Uncomment the following line to display an Edit button in the navigation bar for this view controller. + // self.navigationItem.rightBarButtonItem = self.editButtonItem; +} + + +- (void)setupNavigationBar { + + + self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(back)]; + + } +-(void)back{ + + [self dismissViewControllerAnimated:NO completion:nil]; + +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 0; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + + return 0; +} + +/* +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath]; + + // Configure the cell... + + return cell; +} +*/ + +/* +// 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 From 70be29fca5438ec80b468e188f15d407157f4fb8 Mon Sep 17 00:00:00 2001 From: Bereket Ghebremedhin Date: Fri, 9 Oct 2015 16:30:28 -0400 Subject: [PATCH 02/10] saved from a file switch crisis --- .../xcshareddata/MarsWater.xcscmblueprint | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 MarsWater/MarsWater.xcodeproj/project.xcworkspace/xcshareddata/MarsWater.xcscmblueprint diff --git a/MarsWater/MarsWater.xcodeproj/project.xcworkspace/xcshareddata/MarsWater.xcscmblueprint b/MarsWater/MarsWater.xcodeproj/project.xcworkspace/xcshareddata/MarsWater.xcscmblueprint new file mode 100644 index 0000000..f8e3eb1 --- /dev/null +++ b/MarsWater/MarsWater.xcodeproj/project.xcworkspace/xcshareddata/MarsWater.xcscmblueprint @@ -0,0 +1,30 @@ +{ + "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "6DE2C1D134E7E42733C08A7A796A852DF2F0373A", + "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { + + }, + "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { + "A3AEDD975711D11A3C07EE12753FF388EB8DBC2D" : 0, + "6DE2C1D134E7E42733C08A7A796A852DF2F0373A" : 0 + }, + "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "DF0F57E6-66E2-436C-A7A3-E0FAA1F6209B", + "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { + "A3AEDD975711D11A3C07EE12753FF388EB8DBC2D" : "", + "6DE2C1D134E7E42733C08A7A796A852DF2F0373A" : "unit-2-hw-3\/" + }, + "DVTSourceControlWorkspaceBlueprintNameKey" : "MarsWater", + "DVTSourceControlWorkspaceBlueprintVersion" : 204, + "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "SavingForever\/MarsWater.xcodeproj", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/bereket6725\/unit-2-hw-3.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "6DE2C1D134E7E42733C08A7A796A852DF2F0373A" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/bereket6725\/presetTimerRepo.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "A3AEDD975711D11A3C07EE12753FF388EB8DBC2D" + } + ] +} \ No newline at end of file From 5dac481f98e60d31520d8d29eb4625339d7c07dc Mon Sep 17 00:00:00 2001 From: Bereket Ghebremedhin Date: Fri, 9 Oct 2015 18:10:45 -0400 Subject: [PATCH 03/10] Made some progress, gonna keep pushing though --- .../MarsWater/Base.lproj/Main.storyboard | 14 ++------ .../MarsWater/TaskCreationViewController.h | 7 ++++ .../MarsWater/TaskCreationViewController.m | 23 ++++++++----- .../MarsWater/TasksTableViewController.m | 32 +++++++++++++++++-- 4 files changed, 55 insertions(+), 21 deletions(-) diff --git a/MarsWater/MarsWater/Base.lproj/Main.storyboard b/MarsWater/MarsWater/Base.lproj/Main.storyboard index 9de66b0..736b5fe 100644 --- a/MarsWater/MarsWater/Base.lproj/Main.storyboard +++ b/MarsWater/MarsWater/Base.lproj/Main.storyboard @@ -238,24 +238,13 @@ - - - @@ -268,6 +257,9 @@ + + + diff --git a/MarsWater/MarsWater/TaskCreationViewController.h b/MarsWater/MarsWater/TaskCreationViewController.h index 50a3f16..76f2a33 100644 --- a/MarsWater/MarsWater/TaskCreationViewController.h +++ b/MarsWater/MarsWater/TaskCreationViewController.h @@ -7,9 +7,16 @@ // #import +#import "AppDelegate.h" +#import "TasksTableViewController.h" +#import +#import "Task.h" @interface TaskCreationViewController : UIViewController + +@property (strong, nonatomic) IBOutlet UITextField *addTaskTextField; +@property (nonatomic) Task* task; @end diff --git a/MarsWater/MarsWater/TaskCreationViewController.m b/MarsWater/MarsWater/TaskCreationViewController.m index ef3a056..78be93d 100644 --- a/MarsWater/MarsWater/TaskCreationViewController.m +++ b/MarsWater/MarsWater/TaskCreationViewController.m @@ -7,6 +7,11 @@ // #import "TaskCreationViewController.h" +//#import "AppDelegate.h" +//#import "TasksTableViewController.h" +//#import +//#import "Task.h" + @interface TaskCreationViewController () @@ -14,20 +19,19 @@ @interface TaskCreationViewController () @implementation TaskCreationViewController -- (IBAction)AddTaskButtonTapped:(id)sender { - - - - -} + + - (void)viewDidLoad { [super viewDidLoad]; - + AppDelegate *delegate = [UIApplication sharedApplication].delegate; [self setupNavigationBar]; + + self.task = [NSEntityDescription insertNewObjectForEntityForName:@"Task" inManagedObjectContext:delegate.managedObjectContext]; + // Do any additional setup after loading the view. } @@ -49,8 +53,11 @@ - (void)cancel { } - (void)save { - + self.addTaskTextField.text = self.task.taskDescription; + self.task.createdAt = [NSDate date]; [self dismissViewControllerAnimated:YES completion:nil]; + + // self.list.title = self.titleTextField.text; // self.list.createdAt = [NSDate date]; // diff --git a/MarsWater/MarsWater/TasksTableViewController.m b/MarsWater/MarsWater/TasksTableViewController.m index ec4c661..609e0cb 100644 --- a/MarsWater/MarsWater/TasksTableViewController.m +++ b/MarsWater/MarsWater/TasksTableViewController.m @@ -7,9 +7,14 @@ // #import "TasksTableViewController.h" +#import "AppDelegate.h" +#import +#import "TaskCreationViewController.h" + @interface TasksTableViewController () +@property (nonatomic) NSFetchedResultsController *fetchedResultsController; @end @implementation TasksTableViewController @@ -19,6 +24,29 @@ - (void)viewDidLoad { [self setupNavigationBar]; NSLog(@"%@", self.list.title); + + 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]; + + // Uncomment the following line to preserve selection between presentations. // self.clearsSelectionOnViewWillAppear = NO; @@ -47,12 +75,12 @@ - (void)didReceiveMemoryWarning { #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return 0; + return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return 0; + return self.fetchedResultsController.fetchedObjects.count; } /* From 4ecfc019cd5dfd5c7f0a4e7946de10cd9bacfe18 Mon Sep 17 00:00:00 2001 From: Bereket Ghebremedhin Date: Fri, 9 Oct 2015 18:30:37 -0400 Subject: [PATCH 04/10] tasks not appearing or persisting I think --- .../MarsWater/Base.lproj/Main.storyboard | 2 +- .../MarsWater/TaskCreationViewController.m | 2 +- .../MarsWater/TasksTableViewController.m | 19 +++++++++++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/MarsWater/MarsWater/Base.lproj/Main.storyboard b/MarsWater/MarsWater/Base.lproj/Main.storyboard index 736b5fe..bf3fcd3 100644 --- a/MarsWater/MarsWater/Base.lproj/Main.storyboard +++ b/MarsWater/MarsWater/Base.lproj/Main.storyboard @@ -274,7 +274,7 @@ - + diff --git a/MarsWater/MarsWater/TaskCreationViewController.m b/MarsWater/MarsWater/TaskCreationViewController.m index 78be93d..fe48f8e 100644 --- a/MarsWater/MarsWater/TaskCreationViewController.m +++ b/MarsWater/MarsWater/TaskCreationViewController.m @@ -54,7 +54,7 @@ - (void)cancel { - (void)save { self.addTaskTextField.text = self.task.taskDescription; - self.task.createdAt = [NSDate date]; + self.task.createdAt = [NSDate date]; // not really necessary I gues since the textLabel or detail wont show it but w/e [self dismissViewControllerAnimated:YES completion:nil]; diff --git a/MarsWater/MarsWater/TasksTableViewController.m b/MarsWater/MarsWater/TasksTableViewController.m index 609e0cb..a55c2b0 100644 --- a/MarsWater/MarsWater/TasksTableViewController.m +++ b/MarsWater/MarsWater/TasksTableViewController.m @@ -83,15 +83,26 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger return self.fetchedResultsController.fetchedObjects.count; } -/* +//dont understand this method :( Is it to adjust where the Tasks/list should be? +- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { + + [self.tableView reloadData]; +} + + + - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath]; + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TaskCellIdentifier" forIndexPath:indexPath]; + + Task *task = self.fetchedResultsController.fetchedObjects[indexPath.row]; + cell.textLabel.text = task.taskDescription; + - // Configure the cell... + return cell; } -*/ + /* // Override to support conditional editing of the table view. From c4b017b162a495f6288e080130f2a86a483e8e09 Mon Sep 17 00:00:00 2001 From: Bereket Ghebremedhin Date: Fri, 9 Oct 2015 19:08:19 -0400 Subject: [PATCH 05/10] getting closer --- MarsWater/MarsWater/Base.lproj/Main.storyboard | 2 +- MarsWater/MarsWater/List+CoreDataProperties.h | 2 +- MarsWater/MarsWater/TaskCreationViewController.h | 2 ++ MarsWater/MarsWater/TaskCreationViewController.m | 11 +++++++++++ MarsWater/MarsWater/TasksTableViewController.m | 2 +- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/MarsWater/MarsWater/Base.lproj/Main.storyboard b/MarsWater/MarsWater/Base.lproj/Main.storyboard index bf3fcd3..82cfa0e 100644 --- a/MarsWater/MarsWater/Base.lproj/Main.storyboard +++ b/MarsWater/MarsWater/Base.lproj/Main.storyboard @@ -292,7 +292,7 @@ - + diff --git a/MarsWater/MarsWater/List+CoreDataProperties.h b/MarsWater/MarsWater/List+CoreDataProperties.h index 9ce8d06..ccbccbd 100644 --- a/MarsWater/MarsWater/List+CoreDataProperties.h +++ b/MarsWater/MarsWater/List+CoreDataProperties.h @@ -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 diff --git a/MarsWater/MarsWater/TaskCreationViewController.h b/MarsWater/MarsWater/TaskCreationViewController.h index 76f2a33..c51450e 100644 --- a/MarsWater/MarsWater/TaskCreationViewController.h +++ b/MarsWater/MarsWater/TaskCreationViewController.h @@ -11,6 +11,7 @@ #import "TasksTableViewController.h" #import #import "Task.h" +#import "List.h" @interface TaskCreationViewController : UIViewController @@ -19,4 +20,5 @@ @property (strong, nonatomic) IBOutlet UITextField *addTaskTextField; @property (nonatomic) Task* task; +@property (nonatomic) List* list; @end diff --git a/MarsWater/MarsWater/TaskCreationViewController.m b/MarsWater/MarsWater/TaskCreationViewController.m index fe48f8e..642e07a 100644 --- a/MarsWater/MarsWater/TaskCreationViewController.m +++ b/MarsWater/MarsWater/TaskCreationViewController.m @@ -32,6 +32,7 @@ - (void)viewDidLoad { self.task = [NSEntityDescription insertNewObjectForEntityForName:@"Task" inManagedObjectContext:delegate.managedObjectContext]; + NSLog(@"%@", self.list); // Do any additional setup after loading the view. } @@ -77,6 +78,16 @@ - (void)didReceiveMemoryWarning { // Dispose of any resources that can be recreated. } + +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + + if ([[segue identifier]isEqualToString:@"taskCreateSegue"]){ + TaskCreationViewController *viewController = segue.destinationViewController; + viewController.list = self.list; + NSLog(@"passing this list: %@", self.list); + } + +} /* #pragma mark - Navigation diff --git a/MarsWater/MarsWater/TasksTableViewController.m b/MarsWater/MarsWater/TasksTableViewController.m index a55c2b0..ccaa479 100644 --- a/MarsWater/MarsWater/TasksTableViewController.m +++ b/MarsWater/MarsWater/TasksTableViewController.m @@ -12,7 +12,7 @@ #import "TaskCreationViewController.h" -@interface TasksTableViewController () +@interface TasksTableViewController () @property (nonatomic) NSFetchedResultsController *fetchedResultsController; @end From d73c10a49c74f4ec793339597de7f3cb49a1f995 Mon Sep 17 00:00:00 2001 From: Bereket Ghebremedhin Date: Fri, 9 Oct 2015 19:17:02 -0400 Subject: [PATCH 06/10] missed some stuff in prepareForSegue in the TaskCreationTableViewController and I didnt import the list.h earlier --- MarsWater/MarsWater/TaskCreationViewController.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/MarsWater/MarsWater/TaskCreationViewController.m b/MarsWater/MarsWater/TaskCreationViewController.m index 642e07a..a088492 100644 --- a/MarsWater/MarsWater/TaskCreationViewController.m +++ b/MarsWater/MarsWater/TaskCreationViewController.m @@ -84,6 +84,10 @@ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier]isEqualToString:@"taskCreateSegue"]){ TaskCreationViewController *viewController = segue.destinationViewController; viewController.list = self.list; + + UINavigationController *navController = segue.destinationViewController; + + viewController = navController.viewControllers[0]; NSLog(@"passing this list: %@", self.list); } From 2cab6d31edb0e3a2618ab0e22c39437fb648c78e Mon Sep 17 00:00:00 2001 From: Bereket Ghebremedhin Date: Fri, 9 Oct 2015 19:23:26 -0400 Subject: [PATCH 07/10] prepareForSegue error I missed. There is something weird happening here. Shout outs to Jamaal for help with debugging --- MarsWater/MarsWater/TaskCreationViewController.m | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/MarsWater/MarsWater/TaskCreationViewController.m b/MarsWater/MarsWater/TaskCreationViewController.m index a088492..ce7fdf2 100644 --- a/MarsWater/MarsWater/TaskCreationViewController.m +++ b/MarsWater/MarsWater/TaskCreationViewController.m @@ -82,13 +82,11 @@ - (void)didReceiveMemoryWarning { - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier]isEqualToString:@"taskCreateSegue"]){ - TaskCreationViewController *viewController = segue.destinationViewController; - viewController.list = self.list; - + UINavigationController *navController = segue.destinationViewController; - - viewController = navController.viewControllers[0]; + TaskCreationViewController* viewController = navController.viewControllers[0]; NSLog(@"passing this list: %@", self.list); + viewController.list = self.list; } } From 569af5e299de2fa1a72d3753e63cedd07529b00a Mon Sep 17 00:00:00 2001 From: Bereket Ghebremedhin Date: Fri, 9 Oct 2015 19:47:13 -0400 Subject: [PATCH 08/10] Jamaal is educating me. Also, I might a silly mistake with how I set up the textfield --- .../MarsWater/TaskCreationViewController.m | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/MarsWater/MarsWater/TaskCreationViewController.m b/MarsWater/MarsWater/TaskCreationViewController.m index ce7fdf2..7e71f4e 100644 --- a/MarsWater/MarsWater/TaskCreationViewController.m +++ b/MarsWater/MarsWater/TaskCreationViewController.m @@ -15,6 +15,8 @@ @interface TaskCreationViewController () +@property (nonatomic) NSMutableOrderedSet *taskList; + @end @implementation TaskCreationViewController @@ -54,10 +56,28 @@ - (void)cancel { } - (void)save { - self.addTaskTextField.text = self.task.taskDescription; - self.task.createdAt = [NSDate date]; // not really necessary I gues since the textLabel or detail wont show it but w/e + + self.task.taskDescription = self.addTaskTextField.text; + self.task.createdAt = [NSDate date]; // not really necessary I gues since the textLabel or detail wont show it but w/e + + self.taskList = self.list.task.mutableCopy; + + [self.taskList addObject:self.task]; + + self.list.task = self.taskList; + + NSLog(@"self.list.tasks: %@",self.list.task); + + AppDelegate *delegate = [UIApplication sharedApplication].delegate; + + [delegate.managedObjectContext save:nil]; + [self dismissViewControllerAnimated:YES completion:nil]; + // [self dismiss]; + + + //self.task.taskDescription = self.addTaskTextField.text; // self.list.title = self.titleTextField.text; // self.list.createdAt = [NSDate date]; From 86b16830608b167f259e2f3f63ed32e8f929516a Mon Sep 17 00:00:00 2001 From: Bereket Ghebremedhin Date: Fri, 9 Oct 2015 19:57:01 -0400 Subject: [PATCH 09/10] ran into a new error but very close --- MarsWater/MarsWater/TasksTableViewController.m | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/MarsWater/MarsWater/TasksTableViewController.m b/MarsWater/MarsWater/TasksTableViewController.m index ccaa479..a5c64e2 100644 --- a/MarsWater/MarsWater/TasksTableViewController.m +++ b/MarsWater/MarsWater/TasksTableViewController.m @@ -27,17 +27,20 @@ - (void)viewDidLoad { AppDelegate *delegate = [UIApplication sharedApplication].delegate; - // 1) create an instance of NSFetchRequest with an entity name + // create an instance of NSFetchRequest with an entity name NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Task"]; - // 2) create a sort descriptor + // create a sort descriptor NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"createdAt" ascending:NO]; - // 3) set the sortDescriptors on the fetchRequest + // set the sortDescriptors on the fetchRequest fetchRequest.sortDescriptors = @[sort]; - // 4) create a fetchedResultsController with a fetchRequest and a managedObjectContext, + // NARROWS the search from the fetchRequest based on "list.title" + fetchRequest.predicate = [NSPredicate predicateWithFormat:@"list.title == %@", self.list.title]; + + // 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; From ec91badcfe6b820d4abc2250eecddb879e2dff23 Mon Sep 17 00:00:00 2001 From: Bereket Ghebremedhin Date: Fri, 9 Oct 2015 20:57:17 -0400 Subject: [PATCH 10/10] DONE. But to be honest I only understand about percent of the project. Credits to jamaal, he fixed a good deal of it however as I mentioned above about twenty percent of it still needs a day to sink in. He was amazing though at helping me understand a lot about core data that I wasnt getting though. --- .../MarsWater/Base.lproj/Main.storyboard | 10 ++- .../MarsWater/ListsTableViewController.h | 3 + .../MarsWater/ListsTableViewController.m | 9 +- .../MarsWater/TaskCreationViewController.m | 44 ++++------ .../MarsWater/TasksTableViewController.m | 82 ++++--------------- 5 files changed, 48 insertions(+), 100 deletions(-) diff --git a/MarsWater/MarsWater/Base.lproj/Main.storyboard b/MarsWater/MarsWater/Base.lproj/Main.storyboard index 82cfa0e..c1ff794 100644 --- a/MarsWater/MarsWater/Base.lproj/Main.storyboard +++ b/MarsWater/MarsWater/Base.lproj/Main.storyboard @@ -1,5 +1,5 @@ - + @@ -235,10 +235,12 @@ + + @@ -248,6 +250,7 @@ + @@ -272,6 +275,7 @@ + @@ -280,7 +284,9 @@ + + @@ -327,6 +333,7 @@ + @@ -345,6 +352,7 @@ + diff --git a/MarsWater/MarsWater/ListsTableViewController.h b/MarsWater/MarsWater/ListsTableViewController.h index e83a1d1..99222fd 100644 --- a/MarsWater/MarsWater/ListsTableViewController.h +++ b/MarsWater/MarsWater/ListsTableViewController.h @@ -7,7 +7,10 @@ // #import +#import "List.h" @interface ListsTableViewController : UITableViewController +@property (nonatomic) List *list; + @end diff --git a/MarsWater/MarsWater/ListsTableViewController.m b/MarsWater/MarsWater/ListsTableViewController.m index 3994fd8..dc101b6 100644 --- a/MarsWater/MarsWater/ListsTableViewController.m +++ b/MarsWater/MarsWater/ListsTableViewController.m @@ -9,7 +9,6 @@ #import #import "ListsTableViewController.h" #import "AppDelegate.h" -#import "List.h" #import "TasksTableViewController.h" #import "ListCreationTableViewController.h" @@ -80,12 +79,16 @@ -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if([segue.identifier isEqual: @"TasksSegueIdentifer"]){ - UINavigationController* navigationController = segue.destinationViewController; TasksTableViewController* tableViewController = navigationController.childViewControllers[0]; NSIndexPath* indexPath = [self.tableView indexPathForSelectedRow]; - tableViewController.list = self.fetchedResultsController.fetchedObjects[indexPath.row]; + self.list = self.fetchedResultsController.fetchedObjects[indexPath.row]; + + tableViewController.list = self.list; + + NSLog(@"List Passed: %@",self.list); + } } diff --git a/MarsWater/MarsWater/TaskCreationViewController.m b/MarsWater/MarsWater/TaskCreationViewController.m index 7e71f4e..3b3d36b 100644 --- a/MarsWater/MarsWater/TaskCreationViewController.m +++ b/MarsWater/MarsWater/TaskCreationViewController.m @@ -21,20 +21,15 @@ @interface TaskCreationViewController () @implementation TaskCreationViewController - - - - - - - (void)viewDidLoad { [super viewDidLoad]; - AppDelegate *delegate = [UIApplication sharedApplication].delegate; [self setupNavigationBar]; + AppDelegate *delegate = [UIApplication sharedApplication].delegate; + self.task = [NSEntityDescription insertNewObjectForEntityForName:@"Task" inManagedObjectContext:delegate.managedObjectContext]; - NSLog(@"%@", self.list); + NSLog(@"Current List 2: %@", self.list); // Do any additional setup after loading the view. } @@ -88,28 +83,17 @@ - (void)save { // [self dismissViewControllerAnimated:YES completion:nil]; } - - - - - -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - - -- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { - - if ([[segue identifier]isEqualToString:@"taskCreateSegue"]){ - - UINavigationController *navController = segue.destinationViewController; - TaskCreationViewController* viewController = navController.viewControllers[0]; - NSLog(@"passing this list: %@", self.list); - viewController.list = self.list; - } - -} +//- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { +// +// if ([[segue identifier]isEqualToString:@"taskCreateSegue"]){ +// +// UINavigationController *navController = segue.destinationViewController; +// TaskCreationViewController* viewController = navController.viewControllers[0]; +// NSLog(@"passing this list: %@", self.list); +// viewController.list = self.list; +// } +// +//} /* #pragma mark - Navigation diff --git a/MarsWater/MarsWater/TasksTableViewController.m b/MarsWater/MarsWater/TasksTableViewController.m index a5c64e2..1260a28 100644 --- a/MarsWater/MarsWater/TasksTableViewController.m +++ b/MarsWater/MarsWater/TasksTableViewController.m @@ -22,17 +22,19 @@ @implementation TasksTableViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupNavigationBar]; - NSLog(@"%@", self.list.title); + [self fetchResults]; + NSLog(@"Current List 1: %@", self.list); +} +- (void) fetchResults{ AppDelegate *delegate = [UIApplication sharedApplication].delegate; // create an instance of NSFetchRequest with an entity name NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Task"]; - // create a sort descriptor - NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"createdAt" ascending:NO]; + NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"taskDescription" ascending:NO]; // set the sortDescriptors on the fetchRequest fetchRequest.sortDescriptors = @[sort]; @@ -49,31 +51,17 @@ - (void)viewDidLoad { [self.tableView reloadData]; - - // Uncomment the following line to preserve selection between presentations. - // self.clearsSelectionOnViewWillAppear = NO; - - // Uncomment the following line to display an Edit button in the navigation bar for this view controller. - // self.navigationItem.rightBarButtonItem = self.editButtonItem; } - - - (void)setupNavigationBar { - - self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(back)]; - } +} -(void)back{ [self dismissViewControllerAnimated:NO completion:nil]; } -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} #pragma mark - Table view data source @@ -92,63 +80,25 @@ - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id) [self.tableView reloadData]; } - - - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TaskCellIdentifier" forIndexPath:indexPath]; Task *task = self.fetchedResultsController.fetchedObjects[indexPath.row]; cell.textLabel.text = task.taskDescription; - - - return cell; } - - -/* -// 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. + + if ([[segue identifier]isEqualToString:@"TaskCreateSegue"]){ + + UINavigationController *navController = segue.destinationViewController; + TaskCreationViewController* viewController = navController.viewControllers[0]; + viewController.list = self.list; + + NSLog(@"passing this list: %@", self.list); + } + } -*/ @end