Skip to content

Instantly share code, notes, and snippets.

import SwiftUI
struct ViewProvider: Identifiable {
var id: AnyHashable
var type: Any
var view: AnyView
init<ViewType>(view: ViewType) where ViewType: View & Identifiable {
self.id = view.id
self.type = ViewType.self
@andreweades
andreweades / Monotonic.swift
Last active October 2, 2022 20:12
Generates a fine-grained monotonic Int that can be used as a unique ID (across multiple devices or processes) e.g. as a field in a CKRecord that can be queried
//
// Montonic.swift
// Created by Andrew Eades on 01/04/2020.
// Copyright © 2020 Andrew Eades. All rights reserved.
//
import Foundation
public struct Monotonic {
@andreweades
andreweades / CaseyDisclosureButton
Created September 28, 2021 20:27
Make a disclosure indicator out of a chevron
//
// ContentView.swift
// CaseyDisclosureButton
//
// Created by Andrew Eades on 28/09/2021.
//
import SwiftUI
struct ContentView: View {
@andreweades
andreweades / run-swiftlint.sh
Last active March 15, 2022 07:36
Xcode Benhavior script to run swiftlint
#!/bin/bash
# Written in respond to https://twitter.com/simonbs/status/1437678815866654723
DIR="$(echo "$XcodeProjectPath" | cut -f 1 -d '.')"
if which /opt/homebrew/bin/swiftlint >/dev/null; then
/opt/homebrew/bin/swiftlint $DIR/Sources > $DIR/lint-log.txt
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
@andreweades
andreweades / CodableVersionsTests.swift
Last active May 25, 2021 22:19
Support multiple Codable data format versions and easily migrate even the oldest saved data to the latest version
//
// How to make Codable versioning tolerable
//
// Watch the video: https://youtu.be/BOiFrlii13
//
// Created by Andrew Eades on 25/05/2021.
//
// Run as a test in XCode
import XCTest
@andreweades
andreweades / StringIndicesPlaygroundContent.swift
Last active April 22, 2021 09:53
Ways to index String with an Int.
// How to Index String by Int
// Andrew Eades
// https://www.youtube.com/channel/UC2kOJKUGXfC01YEKH4QjFRA
// Paste this into an Xcode Playground
import Cocoa
var str = "Hello, playground"
@andreweades
andreweades / CloudKitBasics.swift
Created February 19, 2020 17:07 — forked from roymckenzie/CloudKitBasics.swift
Basic Subscription and Fetch manager and setup for CloudKit
import UIKit
import CloudKit
import RealmSwift
/// Handles common methods for subscriptions across multiple databases
enum CloudKitDatabaseSubscription: String {
case `private`
case `public`
}