Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian King KingOfBrian

  • Boston Massachusetts
View GitHub Profile
View PublicationCenter.swift
//
// PublicationCenter.swift
//
// Created by Brian King on 5/17/16.
// Copyright © 2016 Raizlabs. All rights reserved.
//
import Foundation
/// PublicationCenter is an NSNotificationCenter style object that
@KingOfBrian
KingOfBrian / StringKeyDictionary.swift
Last active Mar 6, 2020
Fix encoding of key wrapper types
View StringKeyDictionary.swift
/// Codable doesn't do a good job of Dictionaries with non-String keys.
/// This property wrapper fixes things.
///
/// Context: https://oleb.net/blog/2017/12/dictionary-codable-array/
/// Tests: StringKeyDictionaryTests
@propertyWrapper
public struct StringKeyDictionary<Key: RawRepresentable & Hashable & Decodable, Value: Codable>: Codable where Key.RawValue == String {
public var wrappedValue: [Key: Value]
public init(wrappedValue: [Key: Value]) {
self.wrappedValue = wrappedValue
View gist:adcecf3e24286975b687ef8997581fcd
// Ignore the first few unknowns:
struct MSAssetCollection {
let gradients: [<<Unknown>>]
let images: [<<Unknown>>]
let colors: [MSColor]
let imageCollection: MSImageCollection
}
struct MSImageCollection {
View 0_Failure_Backtrace
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
* frame #0: 0x000000010051d687 libswiftCore.dylib`::_swift_release_dealloc(object=0x0000000101509670) at HeapObject.cpp:558
frame #1: 0x0000000100528166 libswiftCore.dylib`bool swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::doDecrementSlow<(this=0x0000000101509678, oldbits=(bits = 0), dec=1)0, (swift::PerformDeinit)1>(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int) at RefCount.h:1046
frame #2: 0x0000000100526b8c libswiftCore.dylib`bool swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::doDecrement<(this=0x0000000101509678, dec=1)0, (swift::PerformDeinit)1>(unsigned int) at RefCount.h:1104
frame #3: 0x0000000100517381 libswiftCore.dylib`::_swift_release_(swift::HeapObject *) [inlined] swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::decrementAndMaybeDeinit(this=0x0000000101509678, dec=1) at RefCount.h:907
View KSDIdlingWindow.h
//
// KSDIdlingWindow.h
//
// Created by Brian King on 4/13/10.
// Copyright 2010 King Software Designs. All rights reserved.
//
// Based off:
// http://stackoverflow.com/questions/273450/iphone-detecting-user-inactivity-idle-time-since-last-screen-touch
//
View gist:c57b4a5b6faa57cf3876ab826c555f68
protocol AST {
associatedtype NodeType = Self
var children: [NodeType] { get }
}
extension AST where NodeType: AST, NodeType.NodeType == NodeType {
func traverse(check: (Self.NodeType) -> Bool) {
for child in children {
if check(child) {
child.traverse(check: check)
View gist:5502914a7a85fbe7ea67
import Foundation
class FooFun {
@objc
func bat() {
println("bat")
}
}
class Foo :NSObject {
View DeclarationScenarios.md

Describing dispatch scenarios is confusing, and spelling out the code is wordy. In an attempt to keep this document clear and compact, I'll use a short hand to describe the declaration scenarios.

Short hand:

T  = Type (class / struct / enum)
ST = Sub Type (only applies to classes)
P  = Protocol
M1.T = Type from the other module
@KingOfBrian
KingOfBrian / overrides.md
Last active Jun 15, 2017 — forked from erica/overrides.md
Requiring Proactive Overrides for Default Protocol Implementations
View overrides.md

Requiring Proactive Overrides for Default Protocol Implementations

  • Proposal: tbd
  • Author(s): Erica Sadun
  • Status: tbd
  • Review manager: tbd

Introduction

This proposal enhances protocol implementation safety. It incorporates two keywords that cooperate with compiler checks to limit "near miss" implementation errors and accidental member overrides. This is a strictly syntactic system intended to provide greater safety at compile time, and would not affect existing compiled code bases. *** BK: Saying it does not affect implies to me that it's optional. ***

View gist:d9a1be5191059dae9708fc922172ab59
Brians-MBP:SketchyCode bking$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: SketchyCode/SketchyCode/Info.plist
new file: SketchyCode/SketchyCode/JSONBuilder/SketchClass.stencil
new file: SketchyCode/SketchyCode/JSONBuilder/SketchTypeBuilder.swift
new file: SketchyCode/SketchyCode/SketchClasses+Helpers.swift