Skip to content

Instantly share code, notes, and snippets.

@johnno1962
johnno1962 / swiftui.swift
Last active November 6, 2019 23:51
SwiftUI Injection
// First, install InjectionIII.app from the Mac AppStore
// https://apps.apple.com/us/app/injectioniii/id1380446739?mt=12
// Make these changes to your code:
// add the following to application(didFinishLaunchingWithOptions:)
#if DEBUG
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle")?.load()
#endif
@cellularmitosis
cellularmitosis / EmojiPointersDemo.swift
Created August 15, 2018 18:11
Representing pointer values as emoji can be useful for "visually" debugging certain issues, like cell reuse, etc.
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let window = UIWindow(frame: UIScreen.main.bounds)
public protocol ReflectedStringConvertible : CustomStringConvertible { }
extension ReflectedStringConvertible {
public var description: String {
let mirror = Mirror(reflecting: self)
var str = "\(mirror.subjectType)("
var first = true
for (label, value) in mirror.children {
if let label = label {
@ijoshsmith
ijoshsmith / Dictionary+KeysForValue.swift
Created April 14, 2016 15:57
Find keys mapped to a value in Swift dictionary
extension Dictionary where Value: Equatable {
/// Returns all keys mapped to the specified value.
/// ```
/// let dict = ["A": 1, "B": 2, "C": 3]
/// let keys = dict.keysForValue(2)
/// assert(keys == ["B"])
/// assert(dict["B"] == 2)
/// ```
func keysForValue(value: Value) -> [Key] {
return flatMap { (key: Key, val: Value) -> Key? in
@erica
erica / 00-dragndrop.swift
Last active June 28, 2020 14:52
Building an OSX Drag and Drop Playground: Throw the dragndrop.swift into shared Sources and then test out the examples in individual playgrounds. Make sure the assistant is open and set to the timeline. I prefer vertical assistant stacking for this.
import Cocoa
// Support Foundation calls on String
public extension String { public var ns: NSString {return self as NSString} }
/// Custom Labeled Playground-Based Drag-and-Drop window
public class DropView: NSTextField {
// Default action handler
public var handler: ([String]) -> Void = { paths in Swift.print(paths) }
/*
ericasadun.com
Super-basic priority-less layout utilities
*/
#if os(iOS)
import UIKit
#else
@alfredcc
alfredcc / GCD.swift
Created December 25, 2015 02:36
You can use enum and protocol extension to provide GCD convenience API:
You can use enum and protocol extension to provide GCD convenience API:
```
protocol ExcutableQueue {
var queue: dispatch_queue_t { get }
}
extension ExcutableQueue {
func execute(closure: () -> Void) {
dispatch_async(queue, closure)
}