Skip to content

Instantly share code, notes, and snippets.


Jonathan Willing jwilling

View GitHub Profile
jspahrsummers / GHRunLoopWatchdog.h
Created Jan 28, 2015
A class for logging excessive blocking on the main thread
View GHRunLoopWatchdog.h
/// Observes a run loop to detect any stalling or blocking that occurs.
/// This class is thread-safe.
@interface GHRunLoopWatchdog : NSObject
/// Initializes the receiver to watch the specified run loop, using a default
/// stalling threshold.
- (id)initWithRunLoop:(CFRunLoopRef)runLoop;
/// Initializes the receiver to detect when the specified run loop blocks for
andymatuschak / MultiDirectionAdjudicatingScrollView.swift
Created Jan 26, 2015
Source for the Khan Academy app's unusual scrolling interactions
View MultiDirectionAdjudicatingScrollView.swift
// MultiDirectionAdjudicatingScrollView.swift
// Khan Academy
// Created by Andy Matuschak on 12/16/14.
// Copyright (c) 2014 Khan Academy. All rights reserved.
import UIKit
import UIKit.UIGestureRecognizerSubclass
Tricertops / VDM
Last active Aug 30, 2019
How we used MVVM architecture and a reactive framework to build our latest iOS app, from theory to actual code examples.
View VDM

View → Design → Model

iOS applications are usually built with MVC (Model – View – Controller) architecture, which introduces very important concept of separating actual data (Model Layer) and their presentation (View Layer), while the application logic (Controller Layer) stands between them.

View ← Controller → Model

With MVC you typically write most of the code in UIViewController, which usually represents the Controller Layer. View Layer can be easily done in Interface Builder and Model Layer usually doesn’t need a lot of code. The UIViewControleler then holds strong references to both View and Model objects and is responsible for setting them up, handling actions and listening to events.

The problem is, that this middle layer tends to hold too much code and this situation is then jokingly called Massive View Controller. When a single class sets up views, formats data values, handles user input and actions, listens for a bunch of notif

austinzheng / main.swift
Last active Mar 7, 2016
Anonymous class experiment in Swift
View main.swift
import Foundation
protocol SomeDelegateProtocol : class {
func firstFunc() -> String
func secondFunc() -> Bool
func thirdFunc() -> Self
class MyClass {
weak var delegate : SomeDelegateProtocol?
staltz /
Last active May 14, 2021
The introduction to Reactive Programming you've been missing
View NSManagedObjectContext+DebugSwizzling.h
Toggles assertion of Core Data managed object contexts. Only available when DEBUG is defined.
When enabled, your application will throw an exception when accessing or modifying entities in a context other than their own.
void TCBToggleAssertingContextQueues();
depth42 / gist:6886194
Last active Dec 25, 2015
The xib compiler in Xcode 5.0.1 always sets the scaling bit of all NSViews which results in dramatically reduced performance. Until Apple fixes this severe bug, we work around this by patching NSKeyedUnarchiver to clear the bit during decoding of the compiled xib files. By the way: We filed this bug three months ago under rdar://14359398.
View gist:6886194
@interface NSKeyedUnarchiver (Xcode5Fix)
@implementation NSKeyedUnarchiver (Xcode5Fix)
+ (void)load
[self exchangeInstanceMethod:@selector(decodeInt32ForKey:)
swizzlr /
Created Aug 19, 2013
Block Declaration Syntax List, originally by [pcperini](, parsed to markdown for printing with your favourite CSS (I recommend @ttscoff's Marked)

List of Block Declaration Syntaxes

Throughout, let

  • return_type be the type of object/primitive/etc. you'd like to return (commonly void)
  • blockName be the variable name of the block you're creating
  • var_type be the type object/primitive/etc. you'd like to pass as an argument (leave blank for no parameters)
  • varName be the variable name of the given parameter And remember that you can create as many parameters as you'd like.

Blocks as Variables

Possibly the most common for of declaration.

JaviSoto / gist:5906004
Last active Sep 26, 2019
Mark designated initializer at compile time
View gist:5906004
#define MSDesignatedInitializer(__SEL__) __attribute__((unavailable("Invoke the designated initializer `" # __SEL__ "` instead.")))
// Sample usage:
- (instancetype)initWithObject:(id)object;
- (instancetype)init MSDesignatedInitializer(initWithObject:); // <- This even gets auto-complete.
// Now calling init on this class would throw a warning.
// Defines a yet undocumented method to add a warning if super isn't called.
#if __has_attribute(objc_requires_super)
#define NS_REQUIRES_SUPER __attribute((objc_requires_super))