Skip to content

Instantly share code, notes, and snippets.

View jwilling's full-sized avatar

Jonathan Willing jwilling

View GitHub Profile
@joshaber
joshaber / gist:4230872
Created December 7, 2012 04:57
ReactiveCocoa stopwatch
self.startButton.rac_command = [RACCommand command];
self.stopButton.rac_command = [RACCommand command];
__unsafe_unretained id weakSelf = self;
id<RACSignal> tick = [[[[self.startButton.rac_command
map:^(id _) {
RTAFirstView *strongSelf = weakSelf;
// Map each start button click to a new signal that fires every second
// and stops when the stop button is clicked.
return [[RACSignal interval:1] takeUntil:strongSelf.stopButton.rac_command];
@austinzheng
austinzheng / main.swift
Last active March 7, 2016 20:41
Anonymous class experiment in Swift
import Foundation
protocol SomeDelegateProtocol : class {
func firstFunc() -> String
func secondFunc() -> Bool
func thirdFunc() -> Self
}
class MyClass {
weak var delegate : SomeDelegateProtocol?
#if DEBUG
/**
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();
#endif
@andymatuschak
andymatuschak / MultiDirectionAdjudicatingScrollView.swift
Created January 26, 2015 19:31
Source for the Khan Academy app's unusual scrolling interactions
//
// 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
@swizzlr
swizzlr / blockdeclsyntax.md
Created August 19, 2013 13:11
Block Declaration Syntax List, originally by [pcperini](http://stackoverflow.com/a/9201774/929581), 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.

@Tricertops
Tricertops / VDM Architecture.md
Last active August 30, 2019 05:28
How we used MVVM architecture and a reactive framework to build our latest iOS app, from theory to actual code examples.

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

@jamztang
jamztang / LICENSE
Last active November 2, 2019 22:33
UINibDecoderProxy - Use NSProxy to observe what's encoded when views and controllers are created in Interface Builder.
Copyright (c) 2013 Jamz Tang <jamz@jamztang.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
@subdigital
subdigital / pns.m
Created January 5, 2013 21:59
What are your favorite Xcode Snippets? Add them in the comments.
// Property Nonatomic Strong
// Platform: All
// Completion Scopes: ClassInterfaceMethods
@property (nonatomic, strong) <# class_name #> *<# variable_name #>;
@jspahrsummers
jspahrsummers / gist:4305792
Last active April 29, 2021 01:55
CGRectDivideWithPadding illustrations

Simple visual illustrations of how CGRectDivideWithPadding works.

Slicing from CGRectMinXEdge
  +-------+---------+------------>
e |       |         |
d | slice | padding | remainder…
g |       |         |
e |       |         |
@rjw57
rjw57 / CGSPrivate.h
Last active December 2, 2022 06:36
CGSPrivate.h - undocumented APIs for OSX. Re-licensed under MIT licence.
/* CGSPrivate.h -- Header file for undocumented CoreGraphics stuff. */
/* This file is a relicensed portion of DesktopManager and was originally released under
* the terms of the GNU General Public Licence. Original licence text follows the new terms.
* The contents of this file has been re-released by the original author under the following terms:
*
* Copyright (C) 2003, 2004, 2013 Richard J Wareham <richwareham@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software