Skip to content

Instantly share code, notes, and snippets.

View zoejessica's full-sized avatar
🐗
skiing uphill

Zoë Smith zoejessica

🐗
skiing uphill
View GitHub Profile
import Foundation
import CoreData
import CloudKit
// https://github.com/macmade/user-defaults/blob/master/swift/Preferences.swift
/*******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2017 Jean-David Gadina - www.xs-labs.com
@zoejessica
zoejessica / ApproximateValuesSnapshotting.swift
Last active March 4, 2019 01:42
Custom diffing strategy for the pointfree.co swift-snapshot library, to compare dictionaries of named floating point values within a given percentage accuracy threshold.
import Foundation
import SnapshotTesting
import XCTest
public typealias NamesToValues = [String : Double]
public func approximateValues(tolerance percentage: Double) -> SimplySnapshotting<NamesToValues> {
let diffingStrategy = Diffing.approximateValues(tolerance: percentage)
return SimplySnapshotting.init(pathExtension: "json", diffing: diffingStrategy)
}
@zoejessica
zoejessica / list-selection.swift
Created August 18, 2019 23:39
Showing a selection in a SwiftUI List from an observable object (not working atm!)
class Context: ObservableObject {
init(selectedIngredients: Set<Ingredient>, ingredients: [Ingredient]) {
self.selectedIngredients = selectedIngredients
self.ingredients = ingredients
}
@Published var selectedIngredients: Set<Ingredient>
let ingredients: [Ingredient]
}
@zoejessica
zoejessica / PagerView.swift
Created December 26, 2019 21:58 — forked from mecid/PagerView.swift
PagerView in SwiftUI
//
// PagerView.swift
//
// Created by Majid Jabrayilov on 12/5/19.
// Copyright © 2019 Majid Jabrayilov. All rights reserved.
//
import SwiftUI
struct PagerView<Content: View>: View {
let pageCount: Int
@zoejessica
zoejessica / Withable.swift
Created April 24, 2020 23:33 — forked from nicklockwood/Withable.swift
Withable.swift
/// Withable is a simple protocol to make constructing
/// and modifying objects with multiple properties
/// more pleasant (functional, chainable, point-free)
public protocol Withable {
init()
}
public extension Withable {
/// Construct a new instance, setting an arbitrary subset of properties
init(with config: (inout Self) -> Void) {
@zoejessica
zoejessica / DarwinNotificationCenter.swift
Created April 26, 2020 00:22 — forked from AvdLee/DarwinNotificationCenter.swift
A notification center for Darwin Notifications. MIT License applies.
//
// DarwinNotificationCenter.swift
//
// Copyright © 2017 WeTransfer. All rights reserved.
//
import Foundation
/// A Darwin notification payload. It does not contain any userInfo, a Darwin notification is purely event handling.
public struct DarwinNotification {