Skip to content

Xiulan's Homework #8

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 2 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.
Binary file added MarsWater/.DS_Store
Binary file not shown.
235 changes: 124 additions & 111 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 Xiulan Shi on 10/4/15.
// Copyright © 2015 Xiulan Shi. 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 Xiulan Shi on 10/4/15.
// Copyright © 2015 Xiulan Shi. 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 "nyc.c4q.xiulanshi.MarsWater" in the application's documents directory.
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}

Expand Down
424 changes: 281 additions & 143 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 Xiulan Shi on 10/4/15.
// Copyright © 2015 Xiulan Shi. 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 Xiulan Shi on 10/4/15.
// Copyright © 2015 Xiulan Shi. 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 Xiulan Shi on 10/4/15.
// Copyright © 2015 Xiulan Shi. 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 Xiulan Shi on 10/4/15.
// Copyright © 2015 Xiulan Shi. 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 Xiulan Shi on 10/4/15.
// Copyright © 2015 Xiulan Shi. All rights reserved.
//

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

#import <CoreData/CoreData.h>
Expand All @@ -12,9 +12,7 @@
#import "AppDelegate.h"

@interface ListCreationTableViewController ()

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

@property (nonatomic) List *list;

@end
Expand All @@ -29,6 +27,7 @@ - (void)viewDidLoad {
AppDelegate *delegate = [UIApplication sharedApplication].delegate;

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

}

- (void)setupNavigationBar {
Expand All @@ -38,8 +37,6 @@ - (void)setupNavigationBar {
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 {
Expand All @@ -54,6 +51,7 @@ - (void)save {
[delegate.managedObjectContext save:nil];

[self dismissViewControllerAnimated:YES completion:nil];

}

- (IBAction)colorButtonTapped:(UIButton *)sender {
Expand Down
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 Xiulan Shi on 10/4/15.
// Copyright © 2015 Xiulan Shi. All rights reserved.
//

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

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

@interface ListsTableViewController () <NSFetchedResultsControllerDelegate>

Expand All @@ -22,55 +23,81 @@ @implementation ListsTableViewController
- (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];

// 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: @"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 {


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

if (editingStyle == UITableViewCellEditingStyleDelete) {

List *selectedList = self.fetchedResultsController.fetchedObjects[indexPath.row];
AppDelegate *delegate = [UIApplication sharedApplication].delegate;
[delegate.managedObjectContext deleteObject:selectedList];
[delegate.managedObjectContext save:nil];
}
}

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

[self.tableView reloadData];
}

@end
#pragma mark - segue

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

if ([segue.identifier isEqualToString:@"showTask"]){

NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

TasksTableViewController *taskTVC = segue.destinationViewController;

List *list = self.fetchedResultsController.fetchedObjects[indexPath.row];

taskTVC.list = list;
}

}

@end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="8195" systemVersion="15A284" minimumToolsVersion="Automatic">
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="8195" systemVersion="14F27" minimumToolsVersion="Automatic">
<entity name="List" representedClassName="List" syncable="YES">
<attribute name="color" optional="YES" attributeType="Transformable" syncable="YES"/>
<attribute name="createdAt" optional="YES" attributeType="Date" syncable="YES"/>
Expand All @@ -8,15 +8,15 @@
</entity>
<entity name="Task" representedClassName="Task" syncable="YES">
<attribute name="completedAt" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="createdAt" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="createAt" optional="YES" attributeType="Date" syncable="YES"/>
<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"/>
<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="-45" positionY="0" width="128" height="150"/>
<element name="List" positionX="-18" positionY="72" width="128" height="105"/>
</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 Xiulan Shi on 10/4/15.
// Copyright © 2015 Xiulan Shi. 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,12 +16,12 @@ NS_ASSUME_NONNULL_BEGIN
@interface Task (CoreDataProperties)

@property (nullable, nonatomic, retain) NSString *taskDescription;
@property (nullable, nonatomic, retain) NSDate *createdAt;
@property (nullable, nonatomic, retain) NSDate *createAt;
@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) 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 Xiulan Shi on 10/4/15.
// Copyright © 2015 Xiulan Shi. 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 @@ -14,7 +14,7 @@
@implementation Task (CoreDataProperties)

@dynamic taskDescription;
@dynamic createdAt;
@dynamic createAt;
@dynamic dueAt;
@dynamic updatedAt;
@dynamic priority;
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 Xiulan Shi on 10/4/15.
// Copyright © 2015 Xiulan Shi. All rights reserved.
//

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

@class List;

NS_ASSUME_NONNULL_BEGIN

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

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

@implementation Task

Expand Down
16 changes: 16 additions & 0 deletions MarsWater/MarsWater/TaskCreationTableViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// TaskCreationTableViewController.h
// MarsWater
//
// Created by Xiulan Shi on 10/6/15.
// Copyright © 2015 Xiulan Shi. All rights reserved.
//

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

@interface TaskCreationTableViewController : UITableViewController

@property (nonatomic) List *list;

@end
Loading