Skip to content

Instantly share code, notes, and snippets.

View nathanborror's full-sized avatar

Nathan Borror nathanborror

View GitHub Profile
struct Item {
let title: String
}
// Resources
let itemResource = Resource<Item> { callback in
let items = [Item(title: "Foo"), Item(title: "Bar"), Item(title: "Baz")]
callback(items)
}
@nathanborror
nathanborror / gist:9338630
Created March 4, 2014 01:39
constraintsWithVisualFormats
// NSArray *formats = @[
// @"H:|-[textView]-|",
// @"H:|-[moreButton]-|",
// @"V:|-[textView]-[moreButton]-|",
// ];
// [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormats:formats options:0 metrics:nil views:views]];
@implementation NSLayoutConstraint (Common)

Keybase proof

I hereby claim:

  • I am nathanborror on github.
  • I am nathanborror (https://keybase.io/nathanborror) on keybase.
  • I have a public key whose fingerprint is 5D26 8211 E160 5ED3 F5E2 D49E 9533 D273 8B6C BC97

To claim this, I am signing this object:

Host e
HostName 54.208.83.100
User ubuntu
IdentityFile ~/.ssh/your-key-pair.pem
class MasterViewController: UIViewController, UINavigationControllerDelegate {
init() {
super.init(nibName: nil, bundle: nil)
}
}
extension MasterViewController: UITableViewDataSource {
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
@nathanborror
nathanborror / ViewController.swift
Last active August 29, 2015 14:05
Programatic example of UISearchDisplayController
//
// ViewController.swift
// Example
//
// Created by Nathan Borror on 8/28/14.
// Copyright (c) 2014 Nathan Borror. All rights reserved.
//
import UIKit

Auto-Layout

Very simple convenience class to make working with Auto-Layout easier.

class Layout {

    let views: [String:UIView]
    let superview: UIView
import UIKit
struct Styles {
// MARK: Global styles
static let margin:CGFloat = 8.0
static let padding:CGFloat = 8.0
static let tint = UIColor(red: 0.0, green: 0.48, blue: 1.0, alpha: 1.0)
func subscribe() {
let subscription = CKSubscription(recordType: "Item", predicate: NSPredicate(value: true), subscriptionID: "items", options: .FiresOnRecordUpdate | .FiresOnRecordCreation)
subscription.notificationInfo = CKNotificationInfo()
subscription.notificationInfo.alertBody = "New item added"
self.db.saveSubscription(subscription) { (subscription, error) -> Void in
if error != nil {
println(error.localizedDescription)
}
}
}
import UIKit
let words = ["Cat", "Chicken", "Fish", "Dog", "Mouse", "Pig", "Monkey"]
typealias Entry = (Character, [String])
func distinct<T: Equatable>(source: [T]) -> [T] {
var unique = [T]()
for item in source {
if !contains(unique, item) {