"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!
The Core Data way is to add 'total' as an attribue to the model and mark it 'transient'. You then provide the implementation in a subclass interface Marks : NSManagedObject { } @property (nonatomic, readonly) NSDecimalNumber* total; @end @implementation Marks (Calculated) - (NSDecimalNumber*) total { return (3 * self valueForKey:@"answerGradeA") + (2 * self valueForKey:@"answerGradeB") + self valueForKey:@"answerGradeC"; } + (NSSet *)keyPathsForValuesAffectingTotal { return NSSet setWithObjects:@"answerGradeA", @"answerGradeB", @"answerGradeC", nil; } @end This will ensure proper caching and updating of total.
The Core Data way is to add 'total' as an attribue to the model and mark it 'transient'. You then provide the implementation in a subclass. @interface Marks : NSManagedObject { } @property (nonatomic, readonly) NSDecimalNumber* total; @end @implementation Marks (Calculated) - (NSDecimalNumber*) total { return (3 * self valueForKey:@"answerGradeA") + (2 * self valueForKey:@"answerGradeB") + self valueForKey:@"answerGradeC"; } + (NSSet *)keyPathsForValuesAffectingTotal { return NSSet setWithObjects:@"answerGradeA", @"answerGradeB", @"answerGradeC", nil; } @end This will ensure proper caching and updating of total.
As core data assign values to attributes dynamically, isn't it necessary to declare those remaning attributes "answerGradeA" and so in this headerfile along with "total" so that this attribute will know what is the value for key "answerGradeA" while computing. – Kundan Pandit May 3 '10 at 6:13 No, happily the compiler is smart enough to figure that out on its own. Moreover, every line a programmer writes is a potential source of problems and bugs: 'less is more' is as true in programming as it is in life.
Let Core Data do its thing and only nudge it in the right direction when necessary. – Elise van Looij May 25 '10 at 14:25.
(Strictly speaking, total should not be part of CoreData. ) @interface Marks (Calculated) @property (nonatomic, readonly) NSDecimalNumber* total; @end @implementation Marks (Calculated) - (NSDecimalNumber*) total { return whatEverYouLike; } @end.
1: Using categories is ideal, because if you change the data model and make new entity header and implementation files, your category remains separate and intact. – Alex Reynolds Apr 30 '10 at 20:38 Why should total not be part of the Core Data model? @Kundan defines total here as the sum of three specific properties -- it's hard to see why Marks should not be responsible for providing the implementation of total, unless @Kundan has no access to the source code.
– Elise van Looij May 2 '10 at 15:05 That depends on what you are going to do with total. If you want to further process, query, undo ... 'total', then your approach with transient properties works fine (even though transient properties may be tricky). If it is just a matter of adding 3 numbers, I wouldn't probably change the model for that purpose.
– Jens May 2 '10 at 17:29.
I want to post a little modification to Looji's answer. @interface Marks : NSManagedObject { } @property (nonatomic, retain) NSDecimalNumber * answerGradeA; @property (nonatomic, retain) NSDecimalNumber * answerGradeB; @property (nonatomic, retain) NSDecimalNumber * answerGradeC; @property (nonatomic, readonly) NSDecimalNumber* total; @end @implementation Marks (Calculated) - (NSDecimalNumber*) total { return (3 * self valueForKey:@"answerGradeA") + (2 * self valueForKey:@"answerGradeB") + self valueForKey:@"answerGradeC"; } + (NSSet *)keyPathsForValuesAffectingTotal { return NSSet setWithObjects:@"answerGradeA", @"answerGradeB", @"answerGradeC", nil; } @end.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.