WWDC 2006 2007 2008 2009 2010 2011 2012 2013 2014
import Foundation | |
// Here's a pretty typical scenario where you want to encode a polymorphic type - | |
// in this case a Shape type that can be either a Square or Circle. Swift provides | |
// a nice pattern for doing this in a type-safe way using enums: | |
struct Circle: Codable { | |
var radius: Int | |
} |
#!/bin/bash | |
# Useful for downloading Xcode on machines where you don't want to log-in with your Apple ID (e.g. CI | |
# machines, or other low-trust environemnts). | |
# Requires you to manually log-in to the Apple Dev Portal, and extract contents of the ADCDownloadAuth cookie | |
# (easiest way to do it is using Web Inspector, going to the "Storage" Pane, selecting "Cookies" in the left sidebar, | |
# and copying the appropriate value. | |
# | |
# Usage: | |
# curl https://gist.githubusercontent.com/jklausa/5780d5126d97f73b70a91aeab58f7f4a/raw/ | bash -s -- XCODE-URL COOKIE_VALUE |
import UIKit | |
public extension UIColor { | |
var components: (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) { | |
var red: CGFloat = 0 | |
var green: CGFloat = 0 | |
var blue: CGFloat = 0 | |
var alpha: CGFloat = 0 |
#import <UIKit/UIKit.h> | |
typedef NS_ENUM(NSInteger, DBGInterfaceStyleOverride) { | |
DBGInterfaceStyleOverrideNone = 0, | |
DBGInterfaceStyleOverrideLight, | |
DBGInterfaceStyleOverrideDark, | |
}; | |
#ifdef __cplusplus | |
extern "C" { |
State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?
There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.
Here I present a composable pattern for pure state machiness with effects,
typedef enum { | |
AGCommandPriorityLow = -10, | |
AGCommandPriorityDefault = 0, | |
AGCommandPriorityHigh = 10 | |
} AGCommandPriority; | |
@interface AGCommand : NSObject | |
@property(nonatomic, weak) NSObject *firingObject; | |
@property(nonatomic, readonly) SEL action; |
#!/bin/bash | |
# Creates a ramdisk and start Xcode with the DerivedData stored in ramdisk. Also deletes the ramdisk and reset Xcode prefs. | |
# xc_ramdisk.sh | |
# - creates a ramdisk, set Xcode DerivedData to this disk and start Xcode. | |
# - umount a ramdisk, set Xcode DerivedData to default | |
# Stephan Burlot, Coriolis Technologies, http://www.coriolis.ch | |
# | |
# based on Alex Shevchenko xcode_ramdisk.sh script (https://gist.github.com/skeeet/2367298) | |
# based on Diego Freniche xc-launch.sh script (https://github.com/dfreniche/xc-launch) |
#!/bin/sh | |
# Adapted from http://furbo.org/2009/03/03/open-sesame/ | |
if [ -z "$1" ]; then | |
echo "usage: $0 <app> [ Preferences | <document> ]" | |
else | |
app=`ls -1td ~/Library/Application\ Support/iPhone\ Simulator/User/Applications/*/$1.app | head -1` | |
dir=`dirname "$app"` | |
if [ "$2" = "Preferences" ]; then |