Skip to content

Instantly share code, notes, and snippets.

@GeekAndDad
GeekAndDad / TestDecodingFunTests.swift
Last active September 22, 2020 10:13
@chunkyguy on twitter said they were facing a similar challenge to one I was facing, but their challenge actually seemed a little different and potentially easier. So I explored their challenge and created this solution.
//
// TestDecodingFunTests.swift
// TestDecodingFunTests
//
// Created by Dad on 9/22/20.
//
// Poster wanted to be able to parse (visual) "components" out of a json file that would
// have various components of various types.
@GeekAndDad
GeekAndDad / confusing.swift
Last active July 24, 2020 03:49
Computed properties don't call specialized version of functions? Work fine when you call the specialized functions directly but not when those functions are used within a getter or setter it seems… ???
// macOS playground source
// swift 5.3, Xcode 12b2
import Cocoa
struct Foo<A> {
var subVal: Any?
let defaultValue: A
init(defaultValue: A) {
@GeekAndDad
GeekAndDad / detweet.swift
Created June 21, 2020 04:02 — forked from mxcl/detweet.swift
Delete all tweets and favorites older than two months ago. Instructions in comment.
#!/usr/bin/swift sh
import Foundation
import PromiseKit // @mxcl ~> 6.5
import Swifter // @mattdonnelly == b27a89
let swifter = Swifter(
consumerKey: "FILL",
consumerSecret: "ME",
oauthToken: "IN",
oauthTokenSecret: "https://developer.twitter.com/en/docs/basics/apps/overview.html"
@GeekAndDad
GeekAndDad / ContentView.Swift
Created April 3, 2020 23:20
Bug? Two `.alert` modifiers mean only last one works?
//
// ContentView.swift
// TestAlert
//
//
import SwiftUI
struct ContentView: View {
@State private var showAlert1: Bool = false
@GeekAndDad
GeekAndDad / RemindersListToTextEdit.scpt
Last active September 25, 2020 19:02
Hacked together AppleScript to get a list from Reminders and make a new TextEdit document with the items in the list suitable for printing.
tell application "Reminders"
set listNames to {}
repeat with aList in lists
copy name of aList to end of listNames
end repeat
set listName to choose from list listNames with prompt "Select the list to print:"
-- now find list object for the choosen list
set listToPrint to ""
repeat with aList in lists
@GeekAndDad
GeekAndDad / ContentView.swift
Last active February 15, 2020 23:16
Quick hack Mac app to put up a sheet with multi-line text.
import SwiftUI
struct ContentView: View {
@State private var showSheet: Bool = false
@State private var name: String = "Default Name"
var body: some View {
VStack {
Text("Hello, World!")
.frame(maxWidth: .infinity, maxHeight: .infinity)
@GeekAndDad
GeekAndDad / SampleView.swift
Last active February 13, 2020 23:13
Sample to show a blog writer a way to do what they wanted (lined up field values) that actually worked. Put this in an iOS app project and you can preview just this view and if you edit the text in the fields you can see it all adjust. Comment in the .border(Color.green) lines to see the frames of the Text views change dynamically as you type :)
//
// ContentView.swift
// bugtest
//
// Copyright © 2020 Geek & Dad, LLC All rights reserved.
//
import SwiftUI
struct PreferenceTest: View {
@GeekAndDad
GeekAndDad / ContentView.swift
Last active September 25, 2021 00:02
From the blog post "Tiny Hints: a couple of Xcode 11.3 SwiftUI Preview tips"
//
// ContentView.swift
// PreviewsTips2020.01.24
// Updated 2021.09.24
//
// Dad
// @GeekAndDad
//
// Code from blog post:
// https://geekanddad.wordpress.com/2020/01/24/tiny-hints-a-couple-of-xcode-11-3-swiftui-preview-tips/
@GeekAndDad
GeekAndDad / View_printMessage_playground.swift
Last active January 23, 2020 19:17
Simple printMessage extension to SwiftUI's View struct
// from the blog post: https://geekanddad.wordpress.com/2020/01/23/snippet-swiftui-view-printmessage-extension/
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View {
VStack {
TestView(label: "hello", idx: 22)
.font(.title)
@GeekAndDad
GeekAndDad / OpaqueTypesPlayground.swift
Created January 10, 2020 21:02
macOS playground playing with opaque types & protocols.
// paste into new macOS playground
// Xcode 11.3 on 10.15.2
import Cocoa
protocol InfoTypeProtocol {}
protocol Base {
associatedtype InfoType: InfoTypeProtocol
var info: InfoType { get set }