金額属性 [NSNumber double] を持つエンティティがあります... NSDate 属性と 2 つのブール属性 (NSNumber として保存) ... 日付属性のような「金額」属性の合計を取得する方法はありますか?指定された2つの日付の間にあり、ブール属性の1つがYESに設定されています...すべてのエンティティを取得してfor eachに追加しなくても実行できると思います...
// sum of expenses this month
NSFetchRequest *fetchMonthExp = [[NSFetchRequest alloc] init];
NSEntityDescription *entityExp = [NSEntityDescription entityForName:kTransaction inManagedObjectContext:self.context];
[fetchMonthExp setEntity:entityExp];
NSSortDescriptor *sort = [[NSSortDescriptor alloc]
initWithKey:kDate ascending:NO];
[fetchMonthExp setSortDescriptors:[NSArray arrayWithObject:sort]];
NSPredicate *predFetchEx = [NSPredicate predicateWithFormat:@"(isExpense = YES) AND (date > %@) AND (date < %@) AND (isPendingScheduledTransaction = NO) AND (isDebtRepaiment = NO) AND (isLoanRepaiment = NO) AND (isDebt = NO) AND (isLoan = NO)",[self beginingOfMonthForDate:[NSDate date]],[NSDate date]];
[fetchMonthExp setPredicate:predFetchEx];
NSExpression *ex = [NSExpression expressionForFunction:@"sum:"
arguments:[NSArray arrayWithObject:[NSExpression expressionForKeyPath:@"totalAmountInDefaultCurrency"]]];
NSExpressionDescription *ed = [[NSExpressionDescription alloc] init];
[ed setName:@"resultExpSum"];
[ed setExpression:ex];
[ed setExpressionResultType:NSDoubleAttributeType];
NSArray *properties = [NSArray arrayWithObject:ed];
[fetchMonthExp setPropertiesToFetch:properties];
NSError *error1 = nil;
NSArray *resultsEx = [self.context executeFetchRequest:fetchMonthExp error:&error1]; <- EXC_BAD_ACCESS (code = 2, address = 0x0)
if(resultsEx == nil) {
NSLog(@"Failed to fetch exp sum: %@", [error1 localizedDescription]);
NSArray* detailedErrors = [[error1 userInfo] objectForKey:NSDetailedErrorsKey];
if(detailedErrors != nil && [detailedErrors count] > 0) {
for(NSError* detailedError in detailedErrors) {
NSLog(@" DetailedError: %@", [detailedError userInfo]);
}
}
}
そのエラーは何ですか....
-[UIView count]: unrecognized selector sent to instance 0x7856150