Skip to content

Instantly share code, notes, and snippets.

@theoknock
Created October 12, 2021 00:09
Show Gist options
  • Save theoknock/ebc6105604c1732375de2e37e04245ad to your computer and use it in GitHub Desktop.
Save theoknock/ebc6105604c1732375de2e37e04245ad to your computer and use it in GitHub Desktop.
Performing a selector on objects in a copy of an autoreleasing array
- (NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect {
__autoreleasing NSArray<UICollectionViewLayoutAttributes *> * collectionViewLayoutAttributes;
[self performSelector:@selector(changeLayoutAttributes:) withObject:[collectionViewLayoutAttributes = [[NSArray alloc] initWithArray:[super layoutAttributesForElementsInRect:rect] copyItems:TRUE] self]];
return (NSArray<UICollectionViewLayoutAttributes *> *)collectionViewLayoutAttributes;
}
- (void)changeLayoutAttributes:(NSArray<UICollectionViewLayoutAttributes *> *)layoutAttributes {
for (UICollectionViewLayoutAttributes * attribute in layoutAttributes) {
// change attribute code
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment