diff --git a/NohanaImagePicker/AssetDateSectionCreater.swift b/NohanaImagePicker/AssetDateSectionCreater.swift index 2454ecc..0cbf12a 100644 --- a/NohanaImagePicker/AssetDateSectionCreater.swift +++ b/NohanaImagePicker/AssetDateSectionCreater.swift @@ -26,15 +26,15 @@ final class AssetDateSectionCreater { var assetsByDateIndex = 0 for asset in allAssets { if assetsByDateIndex > 0 { - if assetsByDate[assetsByDateIndex - 1].0 == calender.dateComponents([.day, .year, .month], from: (asset.creationDate)!) { + if assetsByDate[assetsByDateIndex - 1].0 == calender.dateComponents([.day, .year, .month], from: (asset.creationDate ?? Date(timeIntervalSince1970: 0))) { assetsByDate[assetsByDateIndex - 1].1.append(asset) } else { - let value = (calender.dateComponents([.day, .year, .month], from: (asset.creationDate)!), [asset]) + let value = (calender.dateComponents([.day, .year, .month], from: (asset.creationDate ?? Date(timeIntervalSince1970: 0))), [asset]) assetsByDate.append(value) assetsByDateIndex += 1 } } else if assetsByDate.count == assetsByDateIndex { - let value = (calender.dateComponents([.day, .year, .month], from: (asset.creationDate)!), [asset]) + let value = (calender.dateComponents([.day, .year, .month], from: (asset.creationDate ?? Date(timeIntervalSince1970: 0))), [asset]) assetsByDate.append(value) assetsByDateIndex += 1 } diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index 3080532..a11096a 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -179,6 +179,9 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo assetListDetailCurrentRow += dateSectionList[section].assetResult.count } } + if assetListDetailCurrentRow >= photoKitAssetList.count { + assetListDetailCurrentRow = photoKitAssetList.count - 1 + } let assetListDetailViewController = segue.destination as! AssetDetailListViewController assetListDetailViewController.photoKitAssetList = photoKitAssetList