Skip to content

Instantly share code, notes, and snippets.

Avatar

Sven A. Schmidt finestructure

View GitHub Profile
View enums Swift book
enum Barcode {
case upc(Int, Int, Int, Int)
case qrCode(String)
}
var productBarcode = Barcode.upc(8, 85909, 51226, 3)
productBarcode = .qrCode("ABCDEFGHIJKLMNOP")
switch productBarcode {
@finestructure
finestructure / compare.swift
Created Feb 23, 2021
NSImage diff speed test
View compare.swift
import Cocoa
func context(for cgImage: CGImage) -> CGContext? {
guard
let space = cgImage.colorSpace,
let context = CGContext(
data: nil,
width: cgImage.width,
height: cgImage.height,
bitsPerComponent: cgImage.bitsPerComponent,
View Multi-version swift build Makefile
clean:
@# just delete specific directories instead of .builds so we don't
@# have to re-fetch dependencies
@rm -f .build/debug
@rm -rf .build/x86_64-apple-macosx/
@rm -rf .build/x86_64-unknown-linux/
@rm -rf .build/x86_64-unknown-linux-gnu/
macos-spm-4.2: clean
@echo
View Wrap.swift
// See: https://www.swiftbysundell.com/tips/inline-wrapping-of-uikit-or-appkit-views-within-swiftui/
import SwiftUI
#if os(iOS)
public struct Wrap<Wrapped: UIView>: UIViewRepresentable {
public typealias Updater = (Wrapped, Context) -> Void
var makeView: () -> Wrapped
@finestructure
finestructure / test_run.swift
Created Apr 9, 2020
Test for adapting a progress handler to Effect.subject
View test_run.swift
import Combine
import ComposableArchitecture
import ComposableArchitectureTestSupport
import XCTest
class MainViewTests: XCTestCase {
func test_run() throws {
// Setup
struct State: Equatable {
var busy = false
@finestructure
finestructure / CAProtocols.swift
Last active Apr 14, 2020
"Guidance protocols" for Composable Architecture
View CAProtocols.swift
//
// CAProtocols.swift
// RequirementEditor
//
// Created by Sven A. Schmidt on 29/03/2020.
// Copyright © 2020 finestructure. All rights reserved.
//
import SwiftUI
View gist:a9dcda2b5c05ce287925428f13a857d6
// Playground generated with 🏟 Arena (https://github.com/finestructure/arena)
// ℹ️ If running the playground fails with an error "no such module ..."
// go to Product -> Build to re-trigger building the SPM package.
// ℹ️ Please restart Xcode if autocomplete is not working.
// Created by running
// arena git@github.com:stephencelis/swift-composable-architecture.git@revision:63b04f284a557d36d5c09d60dafb6e016b3432b8 -n text-field
import ComposableArchitecture
import ComposableArchitectureTestSupport
@finestructure
finestructure / Readme.md
Last active Jun 23, 2020
Homebrew app release
View Readme.md
@finestructure
finestructure / dispatchMain.swift
Created Feb 10, 2020
Swift scripting example use of dispatchMain
View dispatchMain.swift
#!/usr/bin/env swift
import Foundation
import Dispatch
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
print("Done.")
exit(EXIT_SUCCESS)
}
@finestructure
finestructure / make-spm-playground.sh
Last active Aug 12, 2020
Make a playground with access to an SPM library ready for importing
View make-spm-playground.sh
#!/usr/bin/env bash
set -eux
PROJ_NAME=myproj2
PKG_URL=https://github.com/johnsundell/plot.git
PKG_FROM=0.1.0
LIB_NAME=Plot
SWIFT_VERSION=5.1.3
PLATFORM=macos