我有一个NSManagedObject company
带有属性(NSString*) name
和(NSDate*) lastAvailableInterim
.
我想NSArray *companies
根据以下代码示例计算一组公司 ( ) 的汇总值,例如上一个报告日期等于季度末:
- (NSDate*)latestAvailableInterimFor:(NSArray*)companies
{ // returns the maximum interim report date for all companies in the selection, date has to have end month = quarter end
NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
__block NSDate *maxLatestAvailableInterim;
[self.companies enumerateObjectsUsingBlock:^(IBCompany *company, NSUInteger idx, BOOL *stop) {
NSDateComponents *monthComponents = [gregorian components:NSMonthCalendarUnit fromDate:company.latestAvailableInterim];
NSAssert((company.latestAvailableInterim),@"LatestAvailableInterim must be <> NIL!");
NSInteger month = [monthComponents month];
if ( month % 3 == 0 ) maxLatestAvailableInterim = MAX(maxLatestAvailableInterim, company.latestAvailableInterim);
}];
return maxLatestAvailableInterim;
}
从面向对象的角度并基于MVC方案,我将把这段代码放在哪里?
在视图控制器中,它处理结果值或“接近”(NSManagedObject*) company
子类,或者添加一个类别是否有意义NSArray
?
谢谢!