gpt4 book ai didi

ios - 双引号和 NSPredicates

转载 作者:行者123 更新时间:2023-11-28 22:28:18 26 4
gpt4 key购买 nike

我想知道为什么我的谓词在 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]

关于ios - 双引号和 NSPredicates,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18281638/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com