I have two NSDate
s, start date and end date. I want to find all the dates between start and end dates. I tried the code below, but I get the following error:
-[__NSDate length]: unrecognized selector sent to instance 0xa484b30
self.m_maEventsForMonth = [NSMutableArray array];
NSPredicate * sPredicate = [NSPredicate predicateWithFormat:@"(date >= %@) AND (date <= %@)", start, end];
[self.m_maEventsForMonth setArray:[m_maEvents filteredArrayUsingPredicate:sPredicate]];
I also tried making start and end strings as follows, but I get the wrong results:
NSString * sDateStart = [self dateToString:start format:@"M/d/yyyy"];
NSString * sDateEnd = [self dateToString:end format:@"M/d/yyyy"];
self.m_maEventsForMonth = [NSMutableArray array];
NSPredicate * sPredicate = [NSPredicate predicateWithFormat:@"(date BETWEEN %@)", @[sDateStart, sDateEnd]];
[self.m_maEventsForMonth setArray:[m_maEvents filteredArrayUsingPredicate:sPredicate]];
I do not understand what is wrong. Any help would be appreciated.
UPDATE:
My m_maEvents is an NSMutableArray with my custom EventObjects defined as follows:
@interface EventObject : NSObject
{
NSString * title;
NSString * date;
NSString * starttime;
NSString * endtime;
NSString * location;
NSString * url;
NSMutableArray * m_EventTypes;
NSDate * dtDate;
}
@property (nonatomic, retain) NSString * title;
@property (nonatomic, retain) NSString * date;
@property (nonatomic, retain) NSString * starttime;
@property (nonatomic, retain) NSString * endtime;
@property (nonatomic, retain) NSString * location;
@property (nonatomic, retain) NSString * url;
@property (strong, nonatomic) NSMutableArray * m_EventTypes;
@property NSDate * dtDate;
I initialize these objects with the strings and in the init method create the NSDate Object. None of this really matters, my problem is that i do not know how to define the predicate to filter dates between two dates. I have the NSDate Objects and the strings at my disposal but am not sure how to define the predicate. I think it compares using the strings and that is why I get the length error.
Do I need a custom compare method? If so, I have not done one.