Permalink
Browse files

Using NSFetchedResultsController to replace our BehaviorRepository

  • Loading branch information...
1 parent 222e18f commit cff2d5909dbe5ad56ad5a958c5bdb12cf5d8c963 Long Sun committed Apr 20, 2012
@@ -54,12 +54,13 @@
49EBB43A1537D4A5002BBF3C /* UIView+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 49EBB4391537D4A5002BBF3C /* UIView+Additions.m */; };
49EBB43D1537D4BE002BBF3C /* IntrospectManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 49EBB43C1537D4BE002BBF3C /* IntrospectManager.m */; };
49EBB43D1537D4BE002BBF44 /* BindingManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 49EBB43D1537D4BE002BBF43 /* BindingManager.m */; };
- 49EBB43D1537D4BE002BBF4A /* BehaviorRepository.m in Sources */ = {isa = PBXBuildFile; fileRef = 49EBB43D1537D4BE002BBF49 /* BehaviorRepository.m */; };
+ 49EBB43D1537D4BE002BBF4A /* BehaviorResultsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 49EBB43D1537D4BE002BBF49 /* BehaviorResultsController.m */; };
49EBB43D1537D4BE002BBF51 /* NSError+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 49EBB43D1537D4BE002BBF50 /* NSError+Additions.m */; };
49EBB43D1537D4BE002BBF54 /* NSManagedObjectContext+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 49EBB43D1537D4BE002BBF53 /* NSManagedObjectContext+Additions.m */; };
49EBB43D1537D4BE002BBF5C /* DatabaseManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 49EBB43D1537D4BE002BBF5B /* DatabaseManager.m */; };
49EBB43D1537D4BE002BBF5F /* NSDate+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 49EBB43D1537D4BE002BBF5E /* NSDate+Additions.m */; };
49EBB43D1537D4BE002BBF62 /* NSArray+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 49EBB43D1537D4BE002BBF61 /* NSArray+Additions.m */; };
+ 49EBB43D1537D4BE002BBF65 /* NSFetchedResultsController+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 49EBB43D1537D4BE002BBF64 /* NSFetchedResultsController+Additions.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -170,8 +171,8 @@
49EBB43D1537D4BE002BBF43 /* BindingManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BindingManager.m; path = src/BindingManager.m; sourceTree = "<group>"; };
49EBB43D1537D4BE002BBF45 /* BindingManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BindingManager.h; path = src/BindingManager.h; sourceTree = "<group>"; };
49EBB43D1537D4BE002BBF48 /* Macros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Macros.h; path = src/Macros.h; sourceTree = "<group>"; };
- 49EBB43D1537D4BE002BBF49 /* BehaviorRepository.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BehaviorRepository.m; path = src/BehaviorRepository.m; sourceTree = "<group>"; };
- 49EBB43D1537D4BE002BBF4B /* BehaviorRepository.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BehaviorRepository.h; path = src/BehaviorRepository.h; sourceTree = "<group>"; };
+ 49EBB43D1537D4BE002BBF49 /* BehaviorResultsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BehaviorResultsController.m; path = src/BehaviorResultsController.m; sourceTree = "<group>"; };
+ 49EBB43D1537D4BE002BBF4B /* BehaviorResultsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BehaviorResultsController.h; path = src/BehaviorResultsController.h; sourceTree = "<group>"; };
49EBB43D1537D4BE002BBF50 /* NSError+Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSError+Additions.m"; path = "src/NSError+Additions.m"; sourceTree = "<group>"; };
49EBB43D1537D4BE002BBF52 /* NSError+Additions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSError+Additions.h"; path = "src/NSError+Additions.h"; sourceTree = "<group>"; };
49EBB43D1537D4BE002BBF53 /* NSManagedObjectContext+Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSManagedObjectContext+Additions.m"; path = "src/NSManagedObjectContext+Additions.m"; sourceTree = "<group>"; };
@@ -182,6 +183,8 @@
49EBB43D1537D4BE002BBF60 /* NSDate+Additions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSDate+Additions.h"; path = "src/NSDate+Additions.h"; sourceTree = "<group>"; };
49EBB43D1537D4BE002BBF61 /* NSArray+Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSArray+Additions.m"; path = "src/NSArray+Additions.m"; sourceTree = "<group>"; };
49EBB43D1537D4BE002BBF63 /* NSArray+Additions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSArray+Additions.h"; path = "src/NSArray+Additions.h"; sourceTree = "<group>"; };
+ 49EBB43D1537D4BE002BBF64 /* NSFetchedResultsController+Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSFetchedResultsController+Additions.m"; path = "src/NSFetchedResultsController+Additions.m"; sourceTree = "<group>"; };
+ 49EBB43D1537D4BE002BBF66 /* NSFetchedResultsController+Additions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSFetchedResultsController+Additions.h"; path = "src/NSFetchedResultsController+Additions.h"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -255,6 +258,8 @@
4973162515345C8F00E3E5DC /* controllers */ = {
isa = PBXGroup;
children = (
+ 49EBB43D1537D4BE002BBF49 /* BehaviorResultsController.m */,
+ 49EBB43D1537D4BE002BBF4B /* BehaviorResultsController.h */,
49A04A9715344CD90092DC4A /* AppDelegate.h */,
49A04A9815344CD90092DC4A /* AppDelegate.m */,
49CE19BE153D221E00C31041 /* MainViewController.h */,
@@ -323,7 +328,6 @@
isa = PBXGroup;
children = (
4973162615345CA000E3E5DC /* domains */,
- 49A64D0A153E8FDB0064CF90 /* repositories */,
4973162515345C8F00E3E5DC /* controllers */,
49EBB43D1537D4BE002BBF5D /* views */,
49EBB43D1537D4BE002BBF56 /* managers */,
@@ -365,15 +369,6 @@
name = others;
sourceTree = "<group>";
};
- 49A64D0A153E8FDB0064CF90 /* repositories */ = {
- isa = PBXGroup;
- children = (
- 49EBB43D1537D4BE002BBF4B /* BehaviorRepository.h */,
- 49EBB43D1537D4BE002BBF49 /* BehaviorRepository.m */,
- );
- name = repositories;
- sourceTree = "<group>";
- };
49EBB4261537D1D3002BBF3C /* lib */ = {
isa = PBXGroup;
children = (
@@ -402,24 +397,9 @@
49EBB4381537D452002BBF3C /* additions */ = {
isa = PBXGroup;
children = (
- 49EBB43D1537D4BE002BBF63 /* NSArray+Additions.h */,
- 49EBB43D1537D4BE002BBF61 /* NSArray+Additions.m */,
- 49939773153EEEF200A91E7B /* NSSet+Additions.h */,
- 49939774153EEEF200A91E7B /* NSSet+Additions.m */,
- 49EBB43D1537D4BE002BBF60 /* NSDate+Additions.h */,
- 49EBB43D1537D4BE002BBF5E /* NSDate+Additions.m */,
- 49EBB43D1537D4BE002BBF55 /* NSManagedObjectContext+Additions.h */,
- 49EBB43D1537D4BE002BBF53 /* NSManagedObjectContext+Additions.m */,
- 49CE19CC153D607E00C31041 /* NSNumber+Additions.h */,
- 49CE19CD153D607E00C31041 /* NSNumber+Additions.m */,
- 49EBB43D1537D4BE002BBF52 /* NSError+Additions.h */,
- 49EBB43D1537D4BE002BBF50 /* NSError+Additions.m */,
- 495C97FC1535ABF200EEDAFB /* UIGestureRecognizer+Blocks.h */,
- 495C97FD1535ABF200EEDAFB /* UIGestureRecognizer+Blocks.m */,
- 49EBB4141536C8B4002BBF3C /* UIView+Additions.h */,
- 49EBB4391537D4A5002BBF3C /* UIView+Additions.m */,
- 49340A8A153E8B1A006C11A1 /* UITableView+Additions.h */,
- 49340A8B153E8B1A006C11A1 /* UITableView+Additions.m */,
+ 49EBB43D1537D4BE002BBF67 /* Foundation */,
+ 49EBB43D1537D4BE002BBF68 /* UIKit */,
+ 49EBB43D1537D4BE002BBF69 /* CoreData */,
);
name = additions;
sourceTree = "<group>";
@@ -448,6 +428,47 @@
name = views;
sourceTree = "<group>";
};
+ 49EBB43D1537D4BE002BBF67 /* Foundation */ = {
+ isa = PBXGroup;
+ children = (
+ 49939774153EEEF200A91E7B /* NSSet+Additions.m */,
+ 49939773153EEEF200A91E7B /* NSSet+Additions.h */,
+ 49CE19CD153D607E00C31041 /* NSNumber+Additions.m */,
+ 49CE19CC153D607E00C31041 /* NSNumber+Additions.h */,
+ 49EBB43D1537D4BE002BBF50 /* NSError+Additions.m */,
+ 49EBB43D1537D4BE002BBF52 /* NSError+Additions.h */,
+ 49EBB43D1537D4BE002BBF5E /* NSDate+Additions.m */,
+ 49EBB43D1537D4BE002BBF60 /* NSDate+Additions.h */,
+ 49EBB43D1537D4BE002BBF61 /* NSArray+Additions.m */,
+ 49EBB43D1537D4BE002BBF63 /* NSArray+Additions.h */,
+ );
+ name = Foundation;
+ sourceTree = "<group>";
+ };
+ 49EBB43D1537D4BE002BBF68 /* UIKit */ = {
+ isa = PBXGroup;
+ children = (
+ 49EBB4391537D4A5002BBF3C /* UIView+Additions.m */,
+ 49EBB4141536C8B4002BBF3C /* UIView+Additions.h */,
+ 49340A8B153E8B1A006C11A1 /* UITableView+Additions.m */,
+ 49340A8A153E8B1A006C11A1 /* UITableView+Additions.h */,
+ 495C97FD1535ABF200EEDAFB /* UIGestureRecognizer+Blocks.m */,
+ 495C97FC1535ABF200EEDAFB /* UIGestureRecognizer+Blocks.h */,
+ );
+ name = UIKit;
+ sourceTree = "<group>";
+ };
+ 49EBB43D1537D4BE002BBF69 /* CoreData */ = {
+ isa = PBXGroup;
+ children = (
+ 49EBB43D1537D4BE002BBF53 /* NSManagedObjectContext+Additions.m */,
+ 49EBB43D1537D4BE002BBF55 /* NSManagedObjectContext+Additions.h */,
+ 49EBB43D1537D4BE002BBF64 /* NSFetchedResultsController+Additions.m */,
+ 49EBB43D1537D4BE002BBF66 /* NSFetchedResultsController+Additions.h */,
+ );
+ name = CoreData;
+ sourceTree = "<group>";
+ };
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@@ -603,7 +624,7 @@
49EBB43D1537D4BE002BBF44 /* BindingManager.m in Sources */,
4943CECB153AA2A600B823E7 /* DataModel.xcdatamodeld in Sources */,
4943CECF153AA48700B823E7 /* Event.m in Sources */,
- 49EBB43D1537D4BE002BBF4A /* BehaviorRepository.m in Sources */,
+ 49EBB43D1537D4BE002BBF4A /* BehaviorResultsController.m in Sources */,
497659CD153BB8DB00E0D533 /* Binding.m in Sources */,
49EBB43D1537D4BE002BBF51 /* NSError+Additions.m in Sources */,
49EBB43D1537D4BE002BBF54 /* NSManagedObjectContext+Additions.m in Sources */,
@@ -619,6 +640,7 @@
49412AA3153EA07900450C3B /* Behavior.m in Sources */,
49939775153EEEF200A91E7B /* NSSet+Additions.m in Sources */,
494B97F1153EDCDE002801F7 /* SummaryController.m in Sources */,
+ 49EBB43D1537D4BE002BBF65 /* NSFetchedResultsController+Additions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -13,10 +13,12 @@
@interface Behavior : NSManagedObject
-@property (nonatomic, retain) NSString * name;
-@property (nonatomic, retain) NSNumber * rank;
-@property (nonatomic, retain) NSDate * timestamp;
-@property (nonatomic, retain) NSSet *events;
+@property(nonatomic, retain) NSString *name;
+@property(nonatomic, retain) NSNumber *rank;
+@property(nonatomic, retain) NSDate *timestamp;
+@property(nonatomic, retain) NSSet *events;
+
+@property(nonatomic, readonly) NSString *category;
- (Event *)eventForDate:(NSDate *)date;
@@ -25,8 +27,11 @@
@interface Behavior (CoreDataGeneratedAccessors)
- (void)addEventsObject:(Event *)value;
+
- (void)removeEventsObject:(Event *)value;
+
- (void)addEvents:(NSSet *)values;
+
- (void)removeEvents:(NSSet *)values;
@end
View
@@ -1,26 +1,47 @@
-//
-// Behavior.m
-// DailyReview
-//
-// Created by Long Sun on 18/04/12.
-// Copyright (c) 2012 ThoughtWorks. All rights reserved.
-//
-
#import "Behavior.h"
#import "Event.h"
#import "NSSet+Additions.h"
+static NSDictionary *categoryNamesDict = nil;
+
@implementation Behavior
@dynamic name;
@dynamic rank;
@dynamic timestamp;
@dynamic events;
+@dynamic category;
+
++ (void)initialize {
+ if (!categoryNamesDict) {
+ categoryNamesDict = DICT(
+ [NSNumber numberWithInt:1], @"准一功",
+ [NSNumber numberWithInt:3], @"准三功",
+ [NSNumber numberWithInt:5], @"准五功",
+ [NSNumber numberWithInt:10], @"准十功",
+ [NSNumber numberWithInt:30], @"准三十功",
+ [NSNumber numberWithInt:50], @"准五十功",
+ [NSNumber numberWithInt:100], @"准百功",
+ [NSNumber numberWithInt:-1], @"准一过",
+ [NSNumber numberWithInt:-3], @"准三过",
+ [NSNumber numberWithInt:-5], @"准五过",
+ [NSNumber numberWithInt:-10], @"准十过",
+ [NSNumber numberWithInt:-30], @"准三十过",
+ [NSNumber numberWithInt:-50], @"准五十过",
+ [NSNumber numberWithInt:-100], @"准百过"
+ );
+ }
+}
+
- (Event *)eventForDate:(NSDate *)date {
- return [self.events first:^BOOL(Event *event) {
+ return [self.events first:^BOOL(Event *event) {
return [[event date] isEqualToDate:date];
}];
}
+- (NSString *)category {
+ return [categoryNamesDict objectForKey:self.rank];
+}
+
@end
View
@@ -1,19 +0,0 @@
-#import "Behavior.h"
-
-@interface BehaviorRepository : NSObject
-
-+ (BehaviorRepository *)merits;
-
-+ (BehaviorRepository *)demerits;
-
-- (NSUInteger)categoryCount;
-
-- (NSString *)categoryForSection:(NSUInteger)section;
-
-- (NSUInteger)behaviorCountForSection:(NSUInteger)section;
-
-- (Behavior *)behaviorForIndexPath:(NSIndexPath *)indexPath;
-
-- (NSNumber *)totalRank;
-
-@end
Oops, something went wrong.

0 comments on commit cff2d59

Please sign in to comment.