Skip to content

Instantly share code, notes, and snippets.

@alanzeino
Created June 24, 2020 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanzeino/1589a2358572534d52912ee4865dcc38 to your computer and use it in GitHub Desktop.
Save alanzeino/1589a2358572534d52912ee4865dcc38 to your computer and use it in GitHub Desktop.
static UICollectionViewListCell *userCell(UICollectionView *collectionView, NSIndexPath *indexPath, NSArray<RTTweet *> *tweets) {
UICollectionViewListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"UserCell" forIndexPath:indexPath];
UIListContentConfiguration *contentConfiguration = [UIListContentConfiguration valueCellConfiguration];
contentConfiguration.image = nil;
RTTweet *tweet = tweets[indexPath.row];
contentConfiguration.text = tweet.user.username;
contentConfiguration.secondaryText = [tweet.user.followers az_formattedStringForCount];
[[[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:tweet.user.profileUrlFull]
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if (data) {
UIImage *image = [UIImage imageWithData:data];
dispatch_async(dispatch_get_main_queue(), ^{
contentConfiguration.image = image;
});
}
});
}] resume];
contentConfiguration.imageProperties.cornerRadius = 22.f;
contentConfiguration.imageProperties.maximumSize = CGSizeMake(44.f, 44.f);
cell.contentConfiguration = contentConfiguration;
return cell;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment