This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func createDisplayLink() { | |
CVDisplayLinkCreateWithActiveCGDisplays(&displayLink) | |
guard let displayLink = displayLink else { | |
return | |
} | |
let callback: CVDisplayLinkOutputCallback = { (_, _, _, _, _, userInfo) -> CVReturn in | |
let myView = Unmanaged<MyView>.fromOpaque(COpaquePointer(userInfo)).takeUnretainedValue() | |
dispatch_async(dispatch_get_main_queue()) { | |
myView.update() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Security | |
class Keychain { | |
class func save(key: String, data: NSData) -> Bool { | |
let query = [ | |
kSecClass as String : kSecClassGenericPassword as String, | |
kSecAttrAccount as String : key, | |
kSecValueData as String : data ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let plainString = "foo" | |
// Encoding | |
guard let plainData = (plainString as NSString).dataUsingEncoding(NSUTF8StringEncoding) else { | |
fatalError() | |
} | |
let base64String = plainData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0)) | |
print(base64String) // Zm9v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AppKit | |
public extension NSBezierPath { | |
public convenience init(path: CGPath) { | |
self.init() | |
let pathPtr = UnsafeMutablePointer<NSBezierPath>.alloc(1) | |
pathPtr.initialize(self) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/// Given pointer to first element of a C array, invoke a function for each element | |
func enumerateCArray<T>(array: UnsafePointer<T>, count: UInt32, f: (UInt32, T) -> ()) { | |
var ptr = array | |
for i in 0..<count { | |
f(i, ptr.memory) | |
ptr = ptr.successor() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Range+Extensions.swift | |
// IntensityAttributingKit | |
// | |
// Created by Evan Mckee on 3/23/16. | |
// Copyright © 2016 McKeeMaKer. All rights reserved. | |
// | |
import Foundation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
import XCPlayground | |
import PlaygroundSupport | |
class TouchView: NSView { | |
var (path, currentPath) = (NSBezierPath(), NSBezierPath()) | |
override func draw(_ dirtyRect: NSRect) { | |
guard let contextPtr = NSGraphicsContext.current()?.graphicsPort else {return} | |
let context = unsafeBitCast(contextPtr, to: CGContext.self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AppKit | |
import XCPlayground | |
import Cocoa | |
import PlaygroundSupport | |
extension NSLayoutConstraint { | |
convenience init(view item: NSView, to toItem: NSView, attribute: NSLayoutAttribute, constant c: CGFloat = 0) { | |
self.init(item: item, attribute: attribute, | |
relatedBy: .equal, | |
toItem: toItem, attribute: attribute, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol AnyArray{}/*<--Neat trick to assert if a value is an Array, use-full in reflection and when the value is Any but really an array*/ | |
extension Array:AnyArray{}//Maybe rename to ArrayType | |
func recFlatMap<T>(_ arr:[AnyObject]) -> [T]{ | |
var result:[T] = [] | |
Swift.print("arr.count: " + "\(arr.count)") | |
arr.forEach{ | |
if($0 is AnyArray){ | |
let a:[AnyObject] = $0 as! [AnyObject] | |
result += recFlatMap(a) | |
}else{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension URLRequest { | |
/// The cURL representation of the URLRequest, useful for debugging and executing requests outside of the app. | |
var cURLCommand: String { | |
var command = "curl" | |
if let httpMethod = httpMethod { | |
command.append(commandLineArgument: "-X \(httpMethod)") | |
} |
OlderNewer