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スキームに基づいて、このコードをどこに配置しますか?
結果値またはサブクラスの「近く」を処理するView Controllerでは(NSManagedObject*) company
、カテゴリを追加するのは理にかなっていますNSArray
か?
ありがとうございました!