Commits

Allan Davis committed 042385c

Added crud operations to task class

Comments (0)

Files changed (9)

code/TaskList/TaskList.xcodeproj/project.pbxproj

 		CE4C6378163F8D1D00413733 /* Task.m in Sources */ = {isa = PBXBuildFile; fileRef = CE4C6376163F8D1D00413733 /* Task.m */; };
 		CE4C637B163F922D00413733 /* CCViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = CE4C637A163F922D00413733 /* CCViewController.m */; };
 		CE4C637C163F922D00413733 /* CCViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = CE4C637A163F922D00413733 /* CCViewController.m */; };
-		CE4C637F163FA02600413733 /* CCTask.m in Sources */ = {isa = PBXBuildFile; fileRef = CE4C637E163FA02600413733 /* CCTask.m */; };
-		CE4C6380163FA02600413733 /* CCTask.m in Sources */ = {isa = PBXBuildFile; fileRef = CE4C637E163FA02600413733 /* CCTask.m */; };
+		CE4C63EA1642321E00413733 /* Task+CRUD.m in Sources */ = {isa = PBXBuildFile; fileRef = CE4C63E91642321E00413733 /* Task+CRUD.m */; };
 		ED7064F6661B40E5B5F1A624 /* libPods-tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D34B83A7B8FF438AAAC28DE5 /* libPods-tests.a */; };
 /* End PBXBuildFile section */
 
 		CE4C6376163F8D1D00413733 /* Task.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Task.m; path = models/Task.m; sourceTree = "<group>"; };
 		CE4C6379163F922D00413733 /* CCViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCViewController.h; sourceTree = "<group>"; };
 		CE4C637A163F922D00413733 /* CCViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCViewController.m; sourceTree = "<group>"; };
-		CE4C637D163FA02600413733 /* CCTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTask.h; sourceTree = "<group>"; };
-		CE4C637E163FA02600413733 /* CCTask.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCTask.m; sourceTree = "<group>"; };
+		CE4C63E81642321E00413733 /* Task+CRUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Task+CRUD.h"; sourceTree = "<group>"; };
+		CE4C63E91642321E00413733 /* Task+CRUD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "Task+CRUD.m"; sourceTree = "<group>"; };
 		D34B83A7B8FF438AAAC28DE5 /* libPods-tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
 /* End PBXFileReference section */
 
 				CE4C6327163DA0CE00413733 /* Supporting Files */,
 				CE4C6379163F922D00413733 /* CCViewController.h */,
 				CE4C637A163F922D00413733 /* CCViewController.m */,
-				CE4C637D163FA02600413733 /* CCTask.h */,
-				CE4C637E163FA02600413733 /* CCTask.m */,
+				CE4C63E81642321E00413733 /* Task+CRUD.h */,
+				CE4C63E91642321E00413733 /* Task+CRUD.m */,
 			);
 			path = TaskList;
 			sourceTree = "<group>";
 				CE4C633A163DA0CE00413733 /* TaskList.xcdatamodeld in Sources */,
 				CE4C6377163F8D1D00413733 /* Task.m in Sources */,
 				CE4C637B163F922D00413733 /* CCViewController.m in Sources */,
-				CE4C637F163FA02600413733 /* CCTask.m in Sources */,
+				CE4C63EA1642321E00413733 /* Task+CRUD.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
 				CE4C6362163DA28F00413733 /* MathSpec.m in Sources */,
 				CE4C6378163F8D1D00413733 /* Task.m in Sources */,
 				CE4C637C163F922D00413733 /* CCViewController.m in Sources */,
-				CE4C6380163FA02600413733 /* CCTask.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

code/TaskList/TaskList/CCAppDelegate.m

 //    // Override point for customization after application launch.
 //    self.window.backgroundColor = [UIColor whiteColor];
 //    [self.window makeKeyAndVisible];
+    UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
+    UIViewController *controller = navigationController.topViewController;
+    [controller performSelector:@selector(setManagedObjectContext:) withObject:self.managedObjectContext];
     return YES;
 }
 

code/TaskList/TaskList/CCTask.h

-//
-//  CCTask.h
-//  TaskList
-//
-//  Created by Allan Davis on 10/30/12.
-//  Copyright (c) 2012 Cajun Code. All rights reserved.
-//
-
-#import "Task.h"
-
-@interface CCTask : Task
-
-+ (NSArray *) allTaskFromContext:(NSManagedObjectContext *)context;
-
-@end

code/TaskList/TaskList/CCTask.m

-//
-//  CCTask.m
-//  TaskList
-//
-//  Created by Allan Davis on 10/30/12.
-//  Copyright (c) 2012 Cajun Code. All rights reserved.
-//
-
-#import "CCTask.h"
-
-@implementation CCTask
-
-+ (NSArray *) allTaskFromContext:(NSManagedObjectContext *)context{
-    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
-    NSEntityDescription *entity = [NSEntityDescription
-                                   entityForName:@"Task" inManagedObjectContext:context];
-    [fetchRequest setEntity:entity];
-    NSError *error;
-    return [context executeFetchRequest:fetchRequest error:&error];
-    
-}
-@end

code/TaskList/TaskList/CCViewController.m

 //
 
 #import "CCViewController.h"
-#import "CCTask.h"
+#import "Task+CRUD.h"
 #import "CCAppDelegate.h"
 
 @interface CCViewController ()
 - (void)viewDidLoad
 {
     [super viewDidLoad];
-    CCAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
-    self.managedObjectContext = appDelegate.managedObjectContext;
+    //CCAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
+    //self.managedObjectContext = appDelegate.managedObjectContext;
     // 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;
-    self.tasks = [CCTask allTaskFromContext: self.managedObjectContext];
+    self.tasks = [Task allTaskFromContext: self.managedObjectContext];
     [self.tableView reloadData];
 }
 

code/TaskList/TaskList/Task+CRUD.h

+//
+//  Task+CRUD.h
+//  TaskList
+//
+//  Created by Allan Davis on 11/1/12.
+//  Copyright (c) 2012 Cajun Code. All rights reserved.
+//
+
+#import "Task.h"
+
+@interface Task (CRUD)
++ (NSFetchRequest *) createFetchRequestWithContext: (NSManagedObjectContext *)contex;
+
++ (NSArray *) allTaskFromContext:(NSManagedObjectContext *)context;
+
++ (Task *) taskWithName:(NSString*)name fromContext:(NSManagedObjectContext *)context;
+
+- (void)save:(NSError *)error;
+- (void)deleteTask;
+@end

code/TaskList/TaskList/Task+CRUD.m

+//
+//  Task+CRUD.m
+//  TaskList
+//
+//  Created by Allan Davis on 11/1/12.
+//  Copyright (c) 2012 Cajun Code. All rights reserved.
+//
+
+#import "Task+CRUD.h"
+
+@implementation Task (CRUD)
+
++ (NSFetchRequest *) createFetchRequestWithContext: (NSManagedObjectContext *)context{
+    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
+    NSEntityDescription *entity = [NSEntityDescription
+                                   entityForName:@"Task" inManagedObjectContext:context];
+    [fetchRequest setEntity:entity];
+    return fetchRequest;
+}
++ (NSArray *) allTaskFromContext:(NSManagedObjectContext *)context{
+    NSFetchRequest *fetchRequest = [self createFetchRequestWithContext:context];
+    NSError *error;
+    return [context executeFetchRequest:fetchRequest error:&error];
+    
+}
++ (Task *) taskWithName:(NSString*)name fromContext:(NSManagedObjectContext *)context{
+    Task *task = [NSEntityDescription insertNewObjectForEntityForName:@"Trim" inManagedObjectContext:context];
+    task.name = name;
+    NSError *error = nil;
+    [context save:&error];
+    return task;
+}
+
+- (void)save:(NSError *)error{
+    [self.managedObjectContext save: &error];
+}
+
+- (void)deleteTask{
+    [self.managedObjectContext delete:self];
+}
+
+@end

code/TaskList/TaskList/en.lproj/Main.storyboard

         <!--View Controller - Task List-->
         <scene sceneID="Lmp-7j-unw">
             <objects>
-                <tableViewController id="Cdv-XE-68p" customClass="CCViewController" sceneMemberID="viewController">
+                <tableViewController storyboardIdentifier="taskView" id="Cdv-XE-68p" customClass="CCViewController" sceneMemberID="viewController">
                     <tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="TWM-vc-dgx">
                         <rect key="frame" x="0.0" y="64" width="320" height="504"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <point key="canvasLocation" x="-410" y="-33"/>
         </scene>
     </scenes>
+    <classes>
+        <class className="CCViewController" superclassName="UITableViewController">
+            <source key="sourceIdentifier" type="project" relativePath="./Classes/CCViewController.h"/>
+        </class>
+    </classes>
     <simulatedMetricsContainer key="defaultSimulatedMetrics">
         <simulatedStatusBarMetrics key="statusBar"/>
         <simulatedOrientationMetrics key="orientation"/>

presentations/task_list.odp

Binary file modified.