Skip to content

Instantly share code, notes, and snippets.

@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)
View patterns.swift
enum MySpecialEnum {
case someCase
case someCaseWithAssociatedData(String)
case someCaseWithNumbers(Int)
}
func handleSpecialEnum(_ value: MySpecialEnum) {
switch value {
case .someCase:
View BlurrBackgroundButton.swift
public final class BlurryBackgroundButton: UIControl {
public init() {
super.init(frame: .zero)
setup()
}
public override init(frame: CGRect) {
super.init(frame: frame)
setup()
View ShortcutManager.swift
/**
This sample code is available under the MIT license.
*/
@available(iOS 12.0, *)
public final class ShortcutManager {
/**
This enum specifies the different intents available in our app and their various properties for the `INIntent`.
Replace this with your own shortcuts.