Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on using NSDate() without a formatter for date ranges #11

Closed
soundsmitten opened this issue Apr 29, 2016 · 4 comments
Closed

Crash on using NSDate() without a formatter for date ranges #11

soundsmitten opened this issue Apr 29, 2016 · 4 comments

Comments

@soundsmitten
Copy link

Under configure calendar, if I make date ranges using NSDate():

let currentDate = NSDate()
let startComponents = NSDateComponents
let startDate = calendar.dateByAddingComponents(startComponents, toDate: currentDate, options: NSCalendarOptions())
let endComponents = NSDateComponents()
endComponents.month = 1
let endDate = calendar.dateByAddingComponents(endComponents, toDate: currentDate, options: NSCalendarOptions())

I'm getting this error

2016-04-29 17:38:30.217 MyApp[81989:679927] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'attempt to scroll to invalid index path: <NSIndexPath: 0x7b073180> {length = 2, path = 0 - 0}'

I can work around this if I use the an NSDateFormatter to convert a date into a string, and back into a date. I'm not sure if this is me or the library.

let currentDateStr = formatter.stringFromDate(DayService.getFirstDate())
let currentDate = formatter.dateFromString(currentDateStr)!

let startComponents = NSDateComponents()
startComponents.month = -12
let startDate = calendar.dateByAddingComponents(startComponents, toDate: currentDate, options: NSCalendarOptions())                
let endComponents = NSDateComponents()
endComponents.month = 1
let endDate = calendar.dateByAddingComponents(endComponents, toDate: currentDate, options: NSCalendarOptions())


@patchthecode
Copy link
Owner

Acknowledged. Taking a look

@patchthecode patchthecode self-assigned this Apr 29, 2016
@patchthecode patchthecode added this to the Bugs 2.0 milestone Apr 30, 2016
@patchthecode
Copy link
Owner

2 things.

  1. The calendar calls the boundary delegates to find out its date boundary. You are supplying NSDate() to the boundary. Every time NSDate() is called, you are supplying a different date.

Ex.

1st call = 2016-03-01 01:06:03 +0000
2nd call = 2016-03-01 01:07:03 +0000

Difference by a ~ second. Since you are changing the boundary, the calendar thinks you want the boundaries updated and the whole layout reloaded. Now while this is logical that the calendar thinks this, it's sort of dumb.

I will make the following fix -> The calendar will only assume that the developer wants to change the date when the difference in the date is greater than 1 day-unit.

  1. That being said, the calendar should not have crashed. It crashed because after it assumed number 1 above, it deleted its internal date-data in preparation to generate the new one given by your NSDate() function. But it should have done this on the main thread instead of a background one.

The two fixes are done. Testing now. Expect a new code push in a few hrs. In the mean time continue to use the work around. After the fix you should be able to use it like you wanted to.

patchthecode added a commit that referenced this issue Apr 30, 2016
Crash on using NSDate() without a formatter for date ranges #11

Under configure calendar, if I make date ranges using NSDate():

let currentDate = NSDate()
let startComponents = NSDateComponents
let startDate = calendar.dateByAddingComponents(startComponents, toDate: currentDate, options: NSCalendarOptions())
let endComponents = NSDateComponents()
endComponents.month = 1
let endDate = calendar.dateByAddingComponents(endComponents, toDate: currentDate, options: NSCalendarOptions())

I'm getting this error

2016-04-29 17:38:30.217 MyApp[81989:679927] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'attempt to scroll to invalid index path: <NSIndexPath: 0x7b073180> {length = 2, path = 0 - 0}'
@patchthecode
Copy link
Owner

Updated to 2.1.1
Can you let me know if you are still having the issue?

@soundsmitten
Copy link
Author

Yes, 2.1.1 fixes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants