Skip to content

Instantly share code, notes, and snippets.

View dkasaj's full-sized avatar
💭
👨‍💻Coding

Daniel Kašaj dkasaj

💭
👨‍💻Coding
View GitHub Profile
@dkasaj
dkasaj / CenteredItemsScrollTargetBehavior.swift
Created December 21, 2024 11:10
SwiftUI ScrollView Centered Items with ScrollTargetBehavior
import SwiftUI
struct ContentView: View {
private let colors: [Color] = [.red, .orange, .yellow, .green, .blue, .indigo, .purple]
private let itemDimension = UIScreen.main.bounds.width * 0.7
private let itemSpacing = CGFloat(16)
private let scrollViewHorizontalInset = CGFloat(16)
var body: some View {
@dkasaj
dkasaj / ServerChangeTokenCache.swift
Last active October 5, 2021 08:15
Class to handle CloudKit server change tokens
import CloudKit
final class ChangeTokenCache {
// MARK: - Zone support
/// Determines a unique UserDefaults key for storing zone change tokens
/// like from CKFetchRecordZoneChangesOperation
private static func userDefaultsKey(_ zoneID: CKRecordZone.ID) -> String {
return "token_" + zoneID.ownerName + zoneID.zoneName
// Bigger iPhones = any Max, any Plus, iPhone XR, iPhone 11
switch (UITraitCollection.current.horizontalSizeClass, UITraitCollection.current.verticalSizeClass) {
case (.compact, .compact):
// Smaller iPhones in landscape
case (.compact, .regular):
// iPhones in portrait
// iPads in portrait during any split screen,