簡體   English   中英

雙引號和NSPredicates

[英]Double quotes and NSPredicates

我想知道為什么我的謂詞在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;
    }

要替換謂詞字符串中的 ,您必須使用%K格式說明符:

[NSPredicate predicateWithFormat:@"%K >= %@", whatDateShouldEqual, firstDayOfYear]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM