Skip to content

Instantly share code, notes, and snippets.

//
// RBResizer.swift
// Locker
//
// Created by Hampton Catlin on 6/20/14.
// Copyright (c) 2014 rarebit. All rights reserved.
// Updated by Justin Winter on 11/29/15.
//
extension UIImage {
import Foundation
// ============================================
// MARK: - KVObserver Helper
// Modified from Source : https://stackoverflow.com/questions/27292918
class KVObserver: NSObject {
private let keyPath: String
private let block: () -> Void
private weak var object: AnyObject?
@justinlevi
justinlevi / swift-kvo-example.swift
Created November 11, 2015 21:36 — forked from correia/swift-kvo-example.swift
A quick example for how to use Foundation style KVO from Swift. (Official documentation from Apple is forthcoming.)
//
// Swift-KVO
//
// Created by Jim Correia on 6/5/14.
// Copyright (c) 2014-2015 Jim Correia. All rights reserved.
//
// Update: 6/17/2014
//
// KVOContext has gone away; use the same idiom you'd use from Objective-C for the context
//
@justinlevi
justinlevi / PHImageRequest Extension
Last active November 4, 2015 01:38
PHImageRequest convenience Initializer Extension
extension PHImageRequestOptions {
convenience init(deliveryMode: PHImageRequestOptionsDeliveryMode, resizeMode: PHImageRequestOptionsResizeMode){
self.init()
self.deliveryMode = deliveryMode
self.resizeMode = resizeMode
}
@justinlevi
justinlevi / CAToneFileGeneratorSwift
Last active November 18, 2020 15:58
Swift CAToneFileGenerator "Learning Core Audio" Example
//: Playground - noun: a place where people can play
import UIKit
import Foundation
import AudioToolbox
import AVFoundation
import XCPlayground
func CheckError(error:OSStatus) {
if error == 0 {return}
@justinlevi
justinlevi / gist:89da0206bbf461aad745
Created June 26, 2015 20:34
Swift 2 Xcode Beta 2 - Ole Begemann Post Sytax Update
public enum PathElement {
case MoveToPoint(CGPoint)
case AddLineToPoint(CGPoint)
case AddQuadCurveToPoint(CGPoint, CGPoint)
case AddCurveToPoint(CGPoint, CGPoint, CGPoint)
case CloseSubpath
init(element: CGPathElement) {
switch element.type {
case .MoveToPoint: