Skip to content

Instantly share code, notes, and snippets.

View Pretz's full-sized avatar

Alex Pretzlav Pretz

View GitHub Profile
@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

Swift Don'ts

  • Don't add code cruft. Avoid parentheses around conditions in if-statements or with the return keyword. Don't add semicolons except where syntactically demanded in statements or to separate statements on the same line.
  • Don't use ALL_CAPS; use camelCase
  • Don't fight type inference. Use enumeration prefixes, self-references, and class names (with constructors) only when necessary or to clarify coding intent.
  • Don't use var when let is appropriate, especially for properties. The compiler better optimizes let statements for items whose values will not change during their lifetime. For example, Apple writes, "It is good practice to create immutable collections in all cases where the collection does not need to change. Doing so enables the Swift compiler to optimize the performance of the collections you create."
  • Don't use classes when structs will do. Use class
@ngs
ngs / Dictionary.js
Created July 26, 2012 07:53
Script to convert JSON to Objective-C literal
var Dictionary;
if (!Dictionary) {
Dictionary = {};
}
(function () {
'use strict';
function f(n) {
// Format integers to have at least two digits.
@axelarge
axelarge / gist:7386644
Created November 9, 2013 15:36
Objective-C NSComparisonResult for primitives macro
#define COMPARE(A, B) ({ \
__typeof__(A) __a = (A); \
__typeof__(B) __b = (B); \
__a < __b ? NSOrderedAscending : __a == __b ? NSOrderedSame : NSOrderedDescending; \
})
@cdzombak
cdzombak / tgmath.md
Last active July 14, 2016 18:01
fucking tgmath doesn't work with ObjC modules, and Apple has known about this for at least a year and doesn't care about fixing it
@keremk
keremk / Date.playground
Created June 24, 2014 06:56
Swift Date Helpers
// Playground - noun: a place where people can play
import UIKit
var str = "Hello, playground"
enum TimeIntervalUnit {
case Seconds, Minutes, Hours, Days, Months, Years
func dateComponents(interval: Int) -> NSDateComponents {
@dittos
dittos / trac-tickets-to-gh.py
Created July 29, 2010 07:53
Trac tickets to GitHub issues
import sys; reload(sys); sys.setdefaultencoding('utf-8')
import sqlite3
import urllib2
import urllib
import simplejson
login = 'your github id'
token = 'your github api key'
repo = 'username/reponame'