Skip to content

Instantly share code, notes, and snippets.

View ksmandersen's full-sized avatar
🏠
Working from home

Kristian Andersen ksmandersen

🏠
Working from home
View GitHub Profile
import UIKit
class GenericViewController: UIViewController {
var contentView: GenericView {
return view as! GenericView
}
init() {
super.init(nibName: nil, bundle: nil)
import UIKit
class GenericView: UIView {
let stackView = UIStackView()
init() {
super.init(frame: CGRectZero)
setup()
}
@ksmandersen
ksmandersen / RemoteImage.swift
Last active January 20, 2016 14:56
Loading a UIImage into a UIImageView from a NSURL using Forbind
import UIKit
import Forbind
import ForbindExtensions
enum LoadingState {
case NotSet
case Loading
case Loaded
}
@ksmandersen
ksmandersen / swift_segfault
Last active August 29, 2015 14:15
Swift Segfault
case SomeEnum {
case A
case B
}
let someValue = SomeEnum.A
if someValue == .A {
// Do something
}
ant
automake
brew-cask
coreutils
go
hub
libyaml
node
pkg-config
ruby
//
// TableViewDataSource.swift
// QuickReply
//
// Created by Kristian Andersen on 31/07/14.
// Copyright (c) 2014 Robocat. All rights reserved.
//
import UIKit
@ksmandersen
ksmandersen / gist:4d3530eeacd9c41786e5
Created August 4, 2014 09:24
Workaround for: Generic Array DataSource
public class ArrayDataSource<CellType: UIView, ItemType> {
private var items: [ItemType]
private var cellReuseIdentifier: String
private var configureClosure: (CellType, ItemType) -> Void
private var proxy: DataSourceProxy!
private unowned var view: UIView
public init(view: UIView, items: [ItemType], cellReuseIdentifier: String, configureClosure: (CellType, ItemType) -> Void) {
self.items = items
self.cellReuseIdentifier = cellReuseIdentifier
@ksmandersen
ksmandersen / gist:72349811f5100d35c8a2
Last active August 29, 2015 14:04
Generic Array DataSource
class ArrayDataSource<CellType: UIView, ItemType>: NSObject, UITableViewDataSource, UICollectionViewDataSource {
var items: [ItemType]
var cellReuseIdentifier: String
var configureClosure: (CellType, ItemType) -> Void
init(items: [ItemType], cellReuseIdentifier: String, configureClosure: (CellType, ItemType) -> Void) {
self.items = items
self.cellReuseIdentifier = cellReuseIdentifier
self.configureClosure = configureClosure
@ksmandersen
ksmandersen / JSONFixture
Created April 8, 2014 16:42
Load JSON fixture files for your XCTests
@interface JSONFixture : NSObject
+ (id)fixtureDataWithName:(NSString *)fixtureName;
@end
@implementation JSONFixture
+ (id)fixtureDataWithName:(NSString *)fixtureName {
@ksmandersen
ksmandersen / .vimrc
Last active December 25, 2015 12:29
My new minimal vim config for learning vim as go
" ========= Initial setup ===========
" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" backspace in insert mode works like normal editor
set backspace=2
syntax on " syntax highlighting