Skip to content

Instantly share code, notes, and snippets.

final class newTableViewDataSource: NSObject {
private var tableSections: [Section]
init(header: Bool, footer: Bool) {
var sections: [Section] = []
if header {
sections.append(Section.Header(rows: [
Section.Row.HeaderLead(title: "Header"),
final class OldTableDataSource: NSObject {
}
private extension OldTableDataSource {
enum Section: Int {
case Header, Body, Footer
static let numberOfSections = 3
enum HeaderRows: Int {
@ateliercw
ateliercw / AutomaticDequeue.swift
Last active February 18, 2016 22:04
Rough example of improving table view cell registration and dequeuing via generics
protocol AutomaticDequeue {
}
extension AutomaticDequeue where Self: AnyObject {
static var reuseIdentifer: String {
return NSStringFromClass(self) as String
}
}
@ateliercw
ateliercw / profile.sh
Last active May 17, 2016 18:14
Basic worst offenders invocation
xcodebuild -workspace [workspace] -scheme [scheme] clean build OTHER_SWIFT_FLAGS="-Xfrontend -debug-time-function-bodies" | grep .[0-9]ms | grep -v ^0.[0-9]ms | sort -nr > culprits.txt
@ateliercw
ateliercw / xcode_timing_to_json.rb
Created February 16, 2016 02:46
Parses xcode timing data to json
#!/usr/bin/env ruby
require 'json'
def parse_line(line)
units = line.split("\t")
hash = {}
hash[:time] = parse_time(units[0])
hash[:file] = parse_file(units[1])
hash[:function] = units[2]
func differenceFrom(otherRGBA: UIImage.RGBA) -> Int {
return Int(max(alpha, otherRGBA.alpha) - min(alpha, otherRGBA.alpha)) +
Int(max(red, otherRGBA.red) - min(red, otherRGBA.red)) +
Int(max(green, otherRGBA.green) - min(green, otherRGBA.green)) +
Int(max(blue, otherRGBA.green) - min(blue, otherRGBA.blue))
}
func differenceFrom(otherRGBA: UIImage.RGBA) -> Int {
let aDiff = Int(max(alpha, otherRGBA.alpha) - min(alpha, otherRGBA.alpha))
let rDiff = Int(max(red, otherRGBA.red) - min(red, otherRGBA.red))
let gDiff = Int(max(green, otherRGBA.green) - min(green, otherRGBA.green))
let bDiff = Int(max(blue, otherRGBA.green) - min(blue, otherRGBA.blue))
return aDiff + rDiff + gDiff + bDiff
}
@ateliercw
ateliercw / ErrorDecoding.swift
Last active April 8, 2016 03:23
Showing off using errors to speed up JSON decoding
import Foundation
enum JSONDecodingError: ErrorType {
case NilValueForProperty
case TypeMismatch
}
extension Dictionary where Key: StringLiteralConvertible, Value: AnyObject {
// Adds a Swift-y way to get a non-optional type from a key
public extension UIViewKeyframeAnimationOptions {
// This exists because keyframe options doesn't expose the easing for the overall curve
public init(keyframeAnimationsOptions: UIViewKeyframeAnimationOptions, animationCurve: UIViewAnimationCurve) {
let animationOptions: UIViewAnimationOptions
switch animationCurve {
case .EaseIn: animationOptions = .CurveEaseIn
case .EaseInOut: animationOptions = .CurveEaseInOut
case .EaseOut: animationOptions = .CurveEaseOut
case .Linear: animationOptions = .CurveLinear
}
@ateliercw
ateliercw / ForceAppearance.swift
Last active May 13, 2016 02:17
Showing UIAppearance Proxies on on values that aren't normally exposed
private extension AppStyle {
func setupAppearance() {
setupNavBarAppearance()
setupTableViewCellAppearance()
setupTableAppearance()
}
func setupNavBarAppearance() {