@@ -211,9 +211,10 @@ UICollectionViewDelegate, UICollectionViewDataSource, DayViewCellDelegate, Frame
211211 let cvLeft = CGPoint ( x: collectionView. contentOffset. x, y: collectionView. center. y + collectionView. contentOffset. y)
212212 if let path = collectionView. indexPathForItem ( at: cvLeft) ,
213213 let dayViewCell = collectionView. cellForItem ( at: path) as? DayViewCell ,
214- !scrollingToDay, activeDay != dayViewCell. date {
214+ let dayViewCellDate = dayViewCell. date,
215+ !scrollingToDay, activeDay != dayViewCellDate {
215216
216- self . activeDay = dayViewCell . date
217+ self . activeDay = dayViewCellDate
217218 if activeDay > currentPeriod. lateMidLimit {
218219 updatePeriod ( )
219220 }
@@ -264,8 +265,7 @@ UICollectionViewDelegate, UICollectionViewDataSource, DayViewCellDelegate, Frame
264265 }
265266
266267 func collectionView( _ collectionView: UICollectionView , willDisplay cell: UICollectionViewCell , forItemAt indexPath: IndexPath ) {
267- if let dayViewCell = cell as? DayViewCell {
268- let dayDate = dayViewCell. date
268+ if let dayViewCell = cell as? DayViewCell , let dayDate = dayViewCell. date {
269269 self . weekView? . addDayLabel ( forIndexPath: indexPath, withDate: dayDate)
270270 if let allDayEvents = allDayEventsData [ dayDate] {
271271 self . weekView? . addAllDayEvents ( allDayEvents, forIndexPath: indexPath, withDate: dayDate)
@@ -274,8 +274,7 @@ UICollectionViewDelegate, UICollectionViewDataSource, DayViewCellDelegate, Frame
274274 }
275275
276276 func collectionView( _ collectionView: UICollectionView , didEndDisplaying cell: UICollectionViewCell , forItemAt indexPath: IndexPath ) {
277- if let dayViewCell = cell as? DayViewCell {
278- let dayDate = dayViewCell. date
277+ if let dayViewCell = cell as? DayViewCell , let dayDate = dayViewCell. date {
279278 self . weekView? . discardDayLabel ( withDate: dayDate)
280279 if self . weekView? . hasAllDayEvents ( forDate: dayDate) == true {
281280 self . weekView? . removeAllDayEvents ( forDate: dayDate)
@@ -468,8 +467,7 @@ UICollectionViewDelegate, UICollectionViewDataSource, DayViewCellDelegate, Frame
468467 self . eventsData = newEventsData
469468 self . allDayEventsData = newAllDayEvents
470469 for cell in self . dayCollectionView. visibleCells {
471- if let dayViewCell = cell as? DayViewCell {
472- let dayDate = dayViewCell. date
470+ if let dayViewCell = cell as? DayViewCell , let dayDate = dayViewCell. date {
473471 let allThisDayEvents = self . allDayEventsData [ dayDate]
474472 if allThisDayEvents == nil && self . weekView? . hasAllDayEvents ( forDate: dayDate) == true {
475473 self . weekView? . removeAllDayEvents ( forDate: dayDate)
@@ -490,10 +488,12 @@ UICollectionViewDelegate, UICollectionViewDataSource, DayViewCellDelegate, Frame
490488 for dayDate in sortedChangedDays {
491489 self . processEventsData ( forDayDate: dayDate)
492490 }
493- // Redraw days with no changed data
494- for (_, dayViewCell) in self . dayViewCells where !sortedChangedDays. contains ( dayViewCell. date) {
495- dayViewCell. setNeedsLayout ( )
491+ for (_, dayViewCell) in self . dayViewCells {
492+ if let date = dayViewCell. date, !sortedChangedDays. contains ( date) {
493+ dayViewCell. setNeedsLayout ( )
494+ }
496495 }
496+
497497 }
498498
499499 func requestEvents( ) {
0 commit comments