From f503fa53216c8686ffdc7198c94ba8cd2494b03a Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Thu, 7 Dec 2017 23:34:58 +0300 Subject: [PATCH 1/3] fix iOS 9 crash (https://github.com/mokagio/UICollectionViewLeftAlignedLayout/issues/9) --- .../UICollectionViewLeftAlignedLayout.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UICollectionViewLeftAlignedLayout/UICollectionViewLeftAlignedLayout.m b/UICollectionViewLeftAlignedLayout/UICollectionViewLeftAlignedLayout.m index c4bf2b6..ef526cf 100644 --- a/UICollectionViewLeftAlignedLayout/UICollectionViewLeftAlignedLayout.m +++ b/UICollectionViewLeftAlignedLayout/UICollectionViewLeftAlignedLayout.m @@ -57,7 +57,7 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { } - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { - UICollectionViewLayoutAttributes* currentItemAttributes = [[super layoutAttributesForItemAtIndexPath:indexPath] copy]; + UICollectionViewLayoutAttributes* currentItemAttributes = [super layoutAttributesForItemAtIndexPath:indexPath]; UIEdgeInsets sectionInset = [self evaluatedSectionInsetForItemAtIndex:indexPath.section]; BOOL isFirstItemInSection = indexPath.item == 0; From caf0898fddf9f7fb309b7bc5ccee246e821e327f Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Mon, 11 Dec 2017 12:45:57 +0300 Subject: [PATCH 2/3] apply fix only for iOS < 10.0 --- .../UICollectionViewLeftAlignedLayout.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/UICollectionViewLeftAlignedLayout/UICollectionViewLeftAlignedLayout.m b/UICollectionViewLeftAlignedLayout/UICollectionViewLeftAlignedLayout.m index ef526cf..57b11fc 100644 --- a/UICollectionViewLeftAlignedLayout/UICollectionViewLeftAlignedLayout.m +++ b/UICollectionViewLeftAlignedLayout/UICollectionViewLeftAlignedLayout.m @@ -57,7 +57,14 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { } - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { - UICollectionViewLayoutAttributes* currentItemAttributes = [super layoutAttributesForItemAtIndexPath:indexPath]; + UICollectionViewLayoutAttributes* currentItemAttributes; + + if (UIDevice.currentDevice.systemVersion.floatValue < 10.0) { + currentItemAttributes = [super layoutAttributesForItemAtIndexPath:indexPath]; + } else { + currentItemAttributes = [[super layoutAttributesForItemAtIndexPath:indexPath] copy]; + } + UIEdgeInsets sectionInset = [self evaluatedSectionInsetForItemAtIndex:indexPath.section]; BOOL isFirstItemInSection = indexPath.item == 0; From ee7faec96bba28c0f1acd069be4096ab4e1a208c Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Sat, 7 Jul 2018 10:56:57 +0300 Subject: [PATCH 3/3] use @available check --- .../UICollectionViewLeftAlignedLayout.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/UICollectionViewLeftAlignedLayout/UICollectionViewLeftAlignedLayout.m b/UICollectionViewLeftAlignedLayout/UICollectionViewLeftAlignedLayout.m index 57b11fc..c083b88 100644 --- a/UICollectionViewLeftAlignedLayout/UICollectionViewLeftAlignedLayout.m +++ b/UICollectionViewLeftAlignedLayout/UICollectionViewLeftAlignedLayout.m @@ -59,10 +59,10 @@ - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect { - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewLayoutAttributes* currentItemAttributes; - if (UIDevice.currentDevice.systemVersion.floatValue < 10.0) { - currentItemAttributes = [super layoutAttributesForItemAtIndexPath:indexPath]; - } else { + if (@available(iOS 10, *)) { currentItemAttributes = [[super layoutAttributesForItemAtIndexPath:indexPath] copy]; + } else { + currentItemAttributes = [super layoutAttributesForItemAtIndexPath:indexPath]; } UIEdgeInsets sectionInset = [self evaluatedSectionInsetForItemAtIndex:indexPath.section];