Skip to content

Instantly share code, notes, and snippets.

View jslinker's full-sized avatar

Joseph Slinker jslinker

View GitHub Profile
@jslinker
jslinker / SampleFlowLayout.swift
Created January 14, 2019 16:45
UICollectionViewControllerFlowLayout boiler plate. Just fill out the `prepare` function with you layout logic and the rest just works.
class SampleFlowLayout: UICollectionViewLayout {
override func prepare() {
guard let collectionView = self.collectionView else { return }
self.itemAttributes.removeAllObjects()
// go through every section..
for section in 0..<collectionView.numberOfSections {
let numberOfItems = collectionView.numberOfItems(inSection: section)
data = data.map { item -> (t, CGFloat) in
var score: CGFloat!
autoreleasepool {
score = self.converter(item).scoreAgainst(string)
}
return (item, score)
}
.filter { return $0.1 > CGFloat(0) }
.sorted { return $0.1 > $1.1 }
.map { return $0.0 }