SQLite.swift
SQLite.swift copied to clipboard
NSDate fetch crash on some dates
Possible it is better to use optional there ...
I am running into this same problem.
it can be possible, but somebody else have to redesign whole Value methods for it.
You could use custom DateFormatter to pass timeIntervalSince1970
I had the same issue and the fix, for me at least, was a bit subtle.
So I noticed the crash would happen despite stringValue being an acceptable date string. This didn't make sense. Why would it crash when given a perfectly acceptable date value? Turns out this insight was a big clue:
What was actually happening was dateFormatter was causing the problem. Specifically, dateFormatter was being given a different format than the passed in string a bit later in my code, as in:
dateFormatter.dateFormat = "MMM d, yyyy"
This new format would then be applied to the one in SQLite > Foundation.swift, which would, when I had a date with a different format get selected, cause the crash.
In other words I'd give it a string just like yours, but the formatter expected a string in my new format. The date conversion would fail and the optional unwrap would cause a crash.
The fix then, again, for me at least, was to simply set the proper format before the database column was accessed. For example:
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"
..Access database column..
if let lastRefreshedValue = selectrow[_lastRefresh] {
etc...
Alternatively, we can search for an remove any calls to dateFormatter.dateFormat in our project.