Reputation: 4699
I have a method which adds years to a date. While it works on my iPhone 5c iOS8, it fails in the simulator 5s iOS7.1
Here the method:
+ (NSDate *)addYears:(int)years toDate:(NSDate *)datum{
NSCalendar *gregorian = [NSCalendar calendarWithIdentifier:NSGregorianCalendar];
NSDateComponents *components= [[NSDateComponents alloc] init];
[components setYear:years];
return [gregorian dateByAddingComponents:components toDate:datum options:0];
}
The exception is thrown in NSCalendar *gregorian = [NSCalendar calendarWithIdentifier:NSGregorianCalendar];
+[NSCalendar calendarWithIdentifier:]: unrecognized selector sent to class 0x108db9208
Any ideas?
Upvotes: 1
Views: 947
Reputation: 318784
That's a method of EKEventStore
, not NSCalendar
.
You want:
NSCalendar *gregarian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
Upvotes: 2
Reputation: 52538
You must have ignored some severe warnings from your compiler. That class method just doesn't exist.
You may look into the header file to find an init method that does exactly what you want.
Upvotes: 0