Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Artur Rymarz artrmz

🎯
Focusing
View GitHub Profile
View diff_supview.swift
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
View diff_colors.swift
let colors: [UIColor] = [
        .brown,
        .purple,
        .systemBlue,
        .systemRed,
        .systemGray,
        .systemPink
    ]
View diff_snap3.swift
...
let items = colors.shuffled()
snapshot.appendItems(items, toSection: 0)
dataSource.apply(snapshot, animatingDifferences: true)
View diff_snap2.swift
enum Section: CaseIterable {
    case firstSection
case secondSection
}
...
var snapshot = NSDiffableDataSourceSnapshot<Section, UIColor>()
snapshot.appendSections(.firstSection)
snapshot.appendSections(.secondSection)
...
```
View diff_snap.swift
var snapshot = NSDiffableDataSourceSnapshot<Int, UIColor>()
snapshot.appendSections([0])
snapshot.appendItems(items, toSection: 0)
View diff_ds.swift
let dataSource = UICollectionViewDiffableDataSource<Int, UIColor>(collectionView: collectionView) { collectionView, indexPath, item in
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "sampleIdentifier", for: indexPath)
    cell.backgroundColor = item
return cell
}
View DiffableDataSourcesPlayground.swift
//: 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)
View cell_scale.swift
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)
}
View searchbar_usage.swift
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 {
View swiftui_endediting_gesture.swift
.gesture(DragGesture().onChanged { _ in
                UIApplication.shared.endEditing(true)
            })
You can’t perform that action at this time.