Skip to content

Instantly share code, notes, and snippets.

View KingOfBrian's full-sized avatar

Brian King KingOfBrian

  • Boston Massachusetts
View GitHub Profile
@KingOfBrian
KingOfBrian / Remove_final_support_in_protocol_extensions.md
Last active March 12, 2017 02:08
Remove support for final in protocol extensions

Remove final support in protocol extensions

Introduction

This proposal disallows the final keyword when declaring functions in protocol

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
@KingOfBrian
KingOfBrian / overrides.md
Last active June 15, 2017 19:52 — forked from erica/overrides.md
Requiring Proactive Overrides for Default Protocol Implementations

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. ***

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 / gist:5502914a7a85fbe7ea67
Created June 13, 2014 16:39
Swift NSObject subclass
import Foundation
class FooFun {
@objc
func bat() {
println("bat")
}
}
class Foo :NSObject {
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)
//
// 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
//
@KingOfBrian
KingOfBrian / 0_Failure_Backtrace
Last active April 6, 2019 17:11
Test Failures
(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
// Ignore the first few unknowns:
struct MSAssetCollection {
let gradients: [<<Unknown>>]
let images: [<<Unknown>>]
let colors: [MSColor]
let imageCollection: MSImageCollection
}
struct MSImageCollection {
@KingOfBrian
KingOfBrian / StringKeyDictionary.swift
Last active March 6, 2020 15:27
Fix encoding of key wrapper types
/// 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