Skip to content

Instantly share code, notes, and snippets.

View artur-ios-dev's full-sized avatar
🎯
Focusing

Artur Rymarz artur-ios-dev

🎯
Focusing
View GitHub Profile
dataSource.supplementaryViewProvider = { collectionView, kind, indexPath -> UICollectionReusableView? in
    switch kind {
    case UICollectionView.elementKindSectionHeader:
        guard let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sampleHeaderIdentifier", for: indexPath) as? SampleCollectionReusableView else {
            fatalError("Header is not registered")
        }
        headerView.fill(with: "My Awesome Colours")
        return headerView
let colors: [UIColor] = [
        .brown,
        .purple,
        .systemBlue,
        .systemRed,
        .systemGray,
        .systemPink
    ]
...
let items = colors.shuffled()
snapshot.appendItems(items, toSection: 0)
dataSource.apply(snapshot, animatingDifferences: true)
enum Section: CaseIterable {
    case firstSection
case secondSection
}
...
var snapshot = NSDiffableDataSourceSnapshot<Section, UIColor>()
snapshot.appendSections(.firstSection)
snapshot.appendSections(.secondSection)
...
```
var snapshot = NSDiffableDataSourceSnapshot<Int, UIColor>()
snapshot.appendSections([0])
snapshot.appendItems(items, toSection: 0)
let dataSource = UICollectionViewDiffableDataSource<Int, UIColor>(collectionView: collectionView) { collectionView, indexPath, item in
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "sampleIdentifier", for: indexPath)
    cell.backgroundColor = item
return cell
}
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
final class SampleCollectionReusableView: UICollectionReusableView {
private let titleLabel = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
override var isHighlighted: Bool {
didSet {
UIView.animate(withDuration: 0.25, delay: 0, options: [.curveEaseInOut], animations: {
if self.isHighlighted {
self.cardView.transform = CGAffineTransform(scaleX: 0.95, y: 0.95)
} else {
self.cardView.transform = CGAffineTransform.identity
}
}, completion: nil)
}
struct SearchView: View {
let array = "SwiftUI is great but some views might need an extra work".components(separatedBy: " ")
@State private var searchText = ""
var body: some View {
VStack {
SearchBar(text: $searchText)
List {
.gesture(DragGesture().onChanged { _ in
                UIApplication.shared.endEditing(true)
            })