Skip to content

Instantly share code, notes, and snippets.

View vknabel's full-sized avatar

Valentin Knabel vknabel

View GitHub Profile
import Foundation
/// Stores many weak-referenced closures, and may call all in once
/// Throwing closures are not allowed
public struct ClosureSystem<P, R> {
/// The type of a single closure
public typealias ClosureType = (P) -> R
private var elements: [WeakReference<Reference<ClosureType>>]
import UIKit
protocol SegueHandlerType {
typealias SegueIdentifier: RawRepresentable
}
extension SegueHandlerType where
Self: UIViewController,
SegueIdentifier.RawValue == String
{
import UIKit
extension UIImage {
enum AssetIdentifier: String {
case AppIcon = "AppIcon"
case DefaultCover = "default-cover"
}
convenience init!(assetIdentifier: AssetIdentifier) {
import Foundation
func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), closure)
}
import AVFoundation
public typealias AVMediaType = String
public extension AVCaptureDevice {
public class func device(mediaType: AVMediaType, position: AVCaptureDevicePosition) -> AVCaptureDevice? {
let all = AVCaptureDevice.devicesWithMediaType(mediaType) as! [AVCaptureDevice]
for dev in all {
if dev.position == position {
import Foundation
protocol Localized {
typealias RawType
var localized: RawType { get }
}
enum LocalizedString: String, Localized {
case FailureXXXAuthorizationTitle = "FailureXXXAuthorizationTitle"
import UIKit
public extension UITapGestureRecognizer {
public var location: CGPoint {
return self.locationInView(self.view)
}
}
import UIKit
import AVFoundation
class CameraPreviewView: UIView {
override class func layerClass() -> AnyClass {
return AVCaptureVideoPreviewLayer.self
}
var session: AVCaptureSession! {
import AVFoundation
public extension AVCaptureSession {
public func configuration(operation: () -> ()) {
self.beginConfiguration()
operation()
self.commitConfiguration()
}
import UIKit
import AVFoundation
public extension AVCaptureVideoOrientation {
public init(interfaceOrientation: UIInterfaceOrientation) {
switch interfaceOrientation {
case .Unknown:
self = .LandscapeLeft
case .Portrait: