0

私の述語が whatDateShouldEqual と whatDateShouldEqual2 文字列を二重引用符で囲んでいるのはなぜですか? 述語でそれらを取り除く方法はありますか? 述語文字列の等価性を取得しています。

"whatDateShouldEqual" >= CAST(378720000.000000, "NSDate");

二重引用符が私の述語を台無しにしています。

//This method calls the function
- (NSArray *) getAllTasksForCurrentYearForPieChart
{
    NSArray *yearToDatePredicates = [self getPredicateForYearToDateFunctions:[NSString stringWithFormat:@"timeSheetDate"] secondPredicateFilterAtrribute:@"timeSheetDate"];

    NSArray *allTimeSheets = [self getTimeSheetsWithEmployeeId:[NSNumber numberWithInt:[[CANetworkingManager sharedCANetworkingManager].employeeId  intValue]]];

    NSPredicate *predicate =  [yearToDatePredicates objectAtIndex:0];
    [allTimeSheets filteredArrayUsingPredicate:predicate];

    predicate = [yearToDatePredicates objectAtIndex:1];
    [allTimeSheets filteredArrayUsingPredicate:predicate];

    NSArray *uniqueTaskIds = [self getAllUniqueTaskIDsBasedOnArrayOfTimeSheets:allTimeSheets];

    NSArray *uniqueTasks = [self getTasks];

    predicate = [NSPredicate predicateWithFormat:@"taskID IN %@", uniqueTaskIds];
    uniqueTasks = [uniqueTasks filteredArrayUsingPredicate:predicate];

    return uniqueTasks;
}



 - (NSArray *) getPredicateForYearToDateFunctions: (NSString *) whatDateShouldEqual
                      secondPredicateFilterAtrribute: (NSString *) whatDateShouldEqual2
    {
        // This will get the task within the time area
        NSDateFormatter * df = [[NSDateFormatter alloc] init];
        [df setDateFormat:@"yyyy MM dd"];
        NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:[NSDate date]];
        NSInteger year = [components year];

        NSDate *firstDayOfYear = [df dateFromString:[NSString stringWithFormat:@"%d 01 01", year]];
        NSDate *currentDayOfYear = [NSDate date];

        NSMutableArray *holdBothPredicates = [NSMutableArray new];

        [holdBothPredicates addObject:[NSPredicate predicateWithFormat:@"%@ >= %@", whatDateShouldEqual, firstDayOfYear]];

        [holdBothPredicates addObject:[NSPredicate predicateWithFormat:@"%@ <= %@", whatDateShouldEqual2, currentDayOfYear]];

        NSArray *turningToArray = [NSArray arrayWithArray:holdBothPredicates];

        return turningToArray;
    }
4

1 に答える 1

2

述語文字列のキーを置き換えるには、%Kフォーマット指定子を使用する必要があります。

[NSPredicate predicateWithFormat:@"%K >= %@", whatDateShouldEqual, firstDayOfYear]
于 2013-08-16T20:33:34.300 に答える