From 7d03dfeec654c8929dcca2883ee5e953c15c49dc Mon Sep 17 00:00:00 2001 From: "naoto.suzuki" Date: Wed, 1 Dec 2021 14:24:29 +0900 Subject: [PATCH] Avoid crash. --- NohanaImagePicker/AssetDateSectionCreater.swift | 6 +++--- .../AssetListSelectableDateSectionController.swift | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) 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