Skip to content

Instantly share code, notes, and snippets.

Avatar

Nathan Borror nathanborror

View GitHub Profile
View Example.swift
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 Mar 4, 2014
constraintsWithVisualFormats
View gist:9338630
// NSArray *formats = @[
// @"H:|-[textView]-|",
// @"H:|-[moreButton]-|",
// @"V:|-[textView]-[moreButton]-|",
// ];
// [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormats:formats options:0 metrics:nil views:views]];
@implementation NSLayoutConstraint (Common)
View keybase.md

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:

View gist:4657c5be9dab9d33eb23
Host e
HostName 54.208.83.100
User ubuntu
IdentityFile ~/.ssh/your-key-pair.pem
View gist:e257337e73d091423804
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 Aug 29, 2015
Programatic example of UISearchDisplayController
View ViewController.swift
//
// ViewController.swift
// Example
//
// Created by Nathan Borror on 8/28/14.
// Copyright (c) 2014 Nathan Borror. All rights reserved.
//
import UIKit
View autolayout.md

Auto-Layout

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

class Layout {

    let views: [String:UIView]
    let superview: UIView
View Styles.swift
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)
View subscribe.swift
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)
}
}
}
View functional1.swift
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) {