gpt4 book ai didi

iphone - 无法使用NSPredicate从日期数组中获取日期

转载 作者:行者123 更新时间:2023-12-01 19:21:27 24 4
gpt4 key购买 nike

我正在获取两个日期之间的日期数组..并且执行此代码时出现错误,我不知道我哪里出错了:(

我的代码是

  NSArray *Dates = [NSArray arrayWithObjects:@"02-02-2012", @"04-02-2012", @"04-02-2012",      @"03-02-2012",@"04-02-2010", @"04-02-2012", @"04-02-2011", @"09-02-2012", @"12-02-2012 ",      @"11-02-2012", nil];
NSString *startStringDate= @"03-02-2012";
NSString *endStringDate = @"09-02-2012";

//converting NSString to NSDate
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd-MM-yyyy"];
NSDate *StartDate = [dateFormatter dateFromString:startStringDate];
NSDate *endDate = [dateFormatter dateFromString:endStringDate];

// output of StartDate is 03-02-2012 08:37:48 +0000
// output of endDate is 09-02-2012 08:37:48 +0000

//using filteredArrayUsingPredicate to fetch date which comes between StartDate and endDate

NSPredicate *findS = [NSPredicate predicateWithFormat:@"(SELF > %@) AND (SELF < %@)", StartDate, endDate];
NSArray *result = [Dates filteredArrayUsingPredicate:findS];

当我运行此代码时,我得到如下错误:
[__NSDate length]:无法识别的选择器已发送到实例0x982d5a0'

有人可以帮我解决这个问题吗
提前致谢

最佳答案

NSArray *Dates = [NSArray arrayWithObjects:[dateFormatter dateFromString:@"02-02-2012"],[dateFormatter dateFromString:@"04-02-2012"],nil];

这样创建日期数组,而不是尝试工作...

关于iphone - 无法使用NSPredicate从日期数组中获取日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10225409/

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