Skip to content

Instantly share code, notes, and snippets.

Christian Tietze DivineDominion

Block or report user

Report or block DivineDominion

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
Gurdeep0602 / AppStoryboard.swift
Last active Jun 27, 2019
AppStoryboard enumeration
View AppStoryboard.swift
// AppStoryboards.swift
// AppStoryboards
// Created by Gurdeep on 15/12/16.
// Copyright © 2016 Gurdeep. All rights reserved.
import Foundation
import UIKit
russbishop / TypeErasure.swift
Last active Aug 2, 2018
Type erasure with multiple adopting types
View TypeErasure.swift
// Paste me into a playground!
import Cocoa
//: # Basic Setup
protocol FancyProtocol {
associatedtype Thing
func holdPinkyUp(x: Thing)
View valueForKeyTest.swift
//: Playground - noun: a place where people can play
import Cocoa
// When you’re downloading objects from the web, it’s common to need to merge changes
// from the server to already-existing local objects. (If your data model allows for
// mutable objects, as with Core Data, that is.)
// The below is a Swift translation of how I’ve done this in Objective-C.
// Note that it works just fine in Swift — though it does require NSObject subclasses.
preble / NSTextStorageSubclass.swift
Created Feb 9, 2016
Base subclass of NSTextStorage in Swift
View NSTextStorageSubclass.swift
import Cocoa
class SomeTextStorage: NSTextStorage {
private var storage: NSMutableAttributedString
override init() {
storage = NSMutableAttributedString(string: "", attributes: nil)
preble / Completion.swift
Created Jan 20, 2016
A cancellable completion for Swift.
View Completion.swift
final class Completion<R> {
private let closure: (R) -> Void
private var cancelled = false
/// `closure` is called upon completion, if not cancelled.
init(closure: (R) -> Void) {
self.closure = closure
rnapier / helper.swift
Last active Feb 3, 2018
Helper functions
View helper.swift
import Foundation
/// This is going to be one of those things that for many of you is so obvious that it doesn't
/// require saying. But maybe a few of you have never really done this before either. I've been
/// thinking about nested helper functions.
/// I've used little nested helper functions lots of times. I do this when I want a function, but
/// nothing outside of this scope would ever need it.
func doSomething() {
func inc(x: Int) -> Int { return x + 1 }
View nstextview+caret.m
# pragma mark Custom caret
- (void)drawInsertionPointInRect:(NSRect)aRect color:(NSColor *)aColor turnedOn:(BOOL)flag {
aRect.size.width = self.caretWidth;
[super drawInsertionPointInRect:aRect color:aColor turnedOn:flag];
// This is a hack to get the caret drawing to work. I know, I know.
- (void)setNeedsDisplayInRect:(NSRect)invalidRect {
invalidRect.size.width += self.caretWidth - 1;
robb / Example.m
Last active Sep 25, 2018
A macro to convert nullable references to nonnull references while triggering an assert if the expression is actually true. Think of this as unsafe unwrap for Objective-C.
View Example.m
void Log(NSString *foo) {
NSLog(@"%@", foo);
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSDictionary *stuff = @{
@"a": @"Test"
natecook1000 / NSScanner+Swift.swift
Created Mar 3, 2015
Swift-friendly NSScanner methods
View NSScanner+Swift.swift
// NSScanner+Swift.swift
// A set of Swift-idiomatic methods for NSScanner
// (c) 2015 Nate Cook, licensed under the MIT license
import Foundation
extension NSScanner {
// MARK: Strings
kristopherjohnson / DataStore.swift
Created Sep 28, 2014
Swift: Core Data persistence stack
View DataStore.swift
import Foundation
import CoreData
// "Class variables" used in DataStore.sharedDataStore()
private var _instance: DataStore?
private var DataStoreClassLock = NSRecursiveLock()
private let appStoreFilename = "DataStore.sqlite"
private let testStoreFilename = "test_DataStore.sqlite"
You can’t perform that action at this time.