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
373 changes: 373 additions & 0 deletions MarsWater/MarsWater.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// AppDelegate.h
// SavingForever
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
// Created by Zoufishan Mehdi on 10/4/15.
// Copyright © 2015 Zoufishan Mehdi. All rights reserved.
//

#import <UIKit/UIKit.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// AppDelegate.m
// SavingForever
// MarsWater
//
// Created by Michael Kavouras on 10/4/15.
// Copyright © 2015 Michael Kavouras. All rights reserved.
// Created by Zoufishan Mehdi on 10/4/15.
// Copyright © 2015 Zoufishan Mehdi. 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.SavingForever" 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.zoufishanmehdi.MarsWater" in the application's documents directory.
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}

Expand All @@ -60,7 +60,7 @@ - (NSManagedObjectModel *)managedObjectModel {
if (_managedObjectModel != nil) {
return _managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"SavingForever" withExtension:@"momd"];
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"MarsWater" withExtension:@"momd"];
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return _managedObjectModel;
}
Expand All @@ -74,7 +74,7 @@ - (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
// Create the coordinator and store

_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"SavingForever.sqlite"];
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]) {
Expand Down
387 changes: 387 additions & 0 deletions MarsWater/MarsWater/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

File renamed without changes.
40 changes: 40 additions & 0 deletions MarsWater/MarsWater/List+CoreDataProperties.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// List+CoreDataProperties.h
// MarsWater
//
// Created by Zoufishan Mehdi on 10/4/15.
// Copyright © 2015 Zoufishan Mehdi. All rights reserved.
//
// Delete this file and regenerate it using "Create NSManagedObject Subclass…"
// to keep your implementation up to date with your model.
//

#import "List.h"

NS_ASSUME_NONNULL_BEGIN

@interface List (CoreDataProperties)

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

NS_ASSUME_NONNULL_END
19 changes: 19 additions & 0 deletions MarsWater/MarsWater/List+CoreDataProperties.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// List+CoreDataProperties.m
// TryingAgain
//
// Created by Zoufishan Mehdi on 10/4/15.
// Copyright © 2015 Zoufishan Mehdi. All rights reserved.
//

#import "List+CoreDataProperties.h"

@implementation List (CoreDataProperties)

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

@end

24 changes: 24 additions & 0 deletions MarsWater/MarsWater/List.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// List.h
// MarsWater
//
// Created by Zoufishan Mehdi on 10/4/15.
// Copyright © 2015 Zoufishan Mehdi. All rights reserved.
//

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

@class Task;

NS_ASSUME_NONNULL_BEGIN

@interface List : NSManagedObject

// Insert code here to declare functionality of your managed object subclass

@end

NS_ASSUME_NONNULL_END

#import "List+CoreDataProperties.h"
16 changes: 16 additions & 0 deletions MarsWater/MarsWater/List.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// List.m
// MarsWater
//
// Created by Zoufishan Mehdi on 10/4/15.
// Copyright © 2015 Zoufishan Mehdi. All rights reserved.
//

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

@implementation List

// Insert code here to add functionality to your managed object subclass

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

#import <UIKit/UIKit.h>

@interface ListCreationTableViewController : UITableViewController

@end
70 changes: 70 additions & 0 deletions MarsWater/MarsWater/ListCreationTableViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// ListCreationTableViewController.m
// MarsWater
//
// Created by Zoufishan Mehdi on 10/4/15.
// Copyright © 2015 Zoufishan Mehdi. All rights reserved.
//

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

@interface ListCreationTableViewController ()
@property (weak, nonatomic) IBOutlet UITextField *titleTextField;
@property (nonatomic) List *list;

@end

@implementation ListCreationTableViewController

-(void)viewDidLoad {
[super viewDidLoad];

[self setupNavigationBar];

AppDelegate *delegate = [UIApplication sharedApplication].delegate;

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

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

-(void)setupNavigationBar {

//set the title
self.navigationItem.title = @"Create new list";

//set the left button to cancel
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.list.title = self.titleTextField.text;
self.list.createdAt = [NSDate date];

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

[self dismissViewControllerAnimated:YES completion:nil];
}


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

self.list.color = sender.backgroundColor;
}

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

#import <UIKit/UIKit.h>

@interface ListTableViewController : UITableViewController

@end
120 changes: 120 additions & 0 deletions MarsWater/MarsWater/ListTableViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
//
// ListTableViewController.m
// MarsWater
//
// Created by Zoufishan Mehdi on 10/4/15.
// Copyright © 2015 Zoufishan Mehdi. All rights reserved.
//

#import "ListTableViewController.h"
#import <CoreData/CoreData.h>
#import "AppDelegate.h"
#import "List.h"

@interface ListTableViewController () <NSFetchedResultsControllerDelegate>

@property(nonatomic) NSFetchedResultsController *fetchedResultsController;

@end


@implementation ListTableViewController

- (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)set the sortDescriptors on the fetchRequest
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];

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

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.
}
*/

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

[self.tableView reloadData];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>SavingForever.xcdatamodel</string>
<string>MarsWater.xcdatamodel</string>
</dict>
</plist>
Loading