Skip to content

Instantly share code, notes, and snippets.

Avatar

Simon Ljungberg simme

View GitHub Profile
View sqlite question.md

Given these two tables

lists

id name weight
1 Groceries 0
2 Pharmacy 1
3 Misc 2
View DebounceReducer.swift
extension Reducer {
/// Wraps a reducer to inject a debounced action back into the reducer.
///
/// Use this higher order reducer when you want to schedule some work to happen after any other action is recieved by
/// the reducer.
///
/// **Usage:**
/// ```
/// otherReducer.debounceReactiveAction(
/// id: DebounceID(),
@simme
simme / CKError.swift
Created Jun 9, 2021
CloudKit publishers
View CKError.swift
import CloudKit
extension Error {
/// `true` if the error represents a CloudKit conflict.
var isCloudKitConflictError: Bool {
(self as? CKError).map { $0.code == CKError.Code.serverRecordChanged } ?? false
}
/// `true` if the error represents a CloudKit zone deleted error.
@simme
simme / StateStoreCell.swift
Created Dec 10, 2020
Composable Architecutre helpers
View StateStoreCell.swift
import Combine
import ComposableArchitecture
import UIKit
/// The state store cell is a cell superclass designed to work with Composable Architecture state stores. It removes
/// much of the boiler plate involved with creating a custom cell subclass.
open class StateStoreCell<State: Equatable, Action>: UICollectionViewCell {
// MARK: Properties
View CloudKitAccountStatus.swift
import CloudKit
import Combine
/// Fetches the user's CloudKit Account status.
///
/// - Parameter container: The container to check the status in.
///
/// - Returns: A deferred future that resolves to the user's CloudKit Account status.
func getAccountStatus(for container: CKContainer) -> AnyPublisher<CKAccountStatus, Error> {
Deferred {
View CellConfinable.swift
import UIKit
public protocol CellConfinable: UIView {
associatedtype Item
var isSelected: Bool { get set }
var isHighlighted: Bool { get set }
func prepareForReuse()
func configure(for item: Item)
}
View CombineFrame.swift
private final class OfferingButton: UIViewController {
@Published private var frame: CGRect = .zero
private var subscriptions: [AnyCancellable] = []
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
$frame.removeDuplicates()
View collectionview.swift
import SwiftUI
extension String: Identifiable {
public var id: String { self }
}
struct CollectionViewSizeKey<ID: Hashable>: PreferenceKey {
typealias Value = [ID: CGSize]
static var defaultValue: [ID: CGSize] { [:] }
View scrollthing.swift
import SwiftUI
struct RoundedCorner: Shape {
var radius: CGFloat = .infinity
var corners: UIRectCorner = .allCorners
func path(in rect: CGRect) -> Path {
let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
return Path(path.cgPath)
View scrollthing.swift
import SwiftUI
struct RoundedCorner: Shape {
var radius: CGFloat = .infinity
var corners: UIRectCorner = .allCorners
func path(in rect: CGRect) -> Path {
let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
return Path(path.cgPath)