This file contains hidden or 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 hidden or 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 hidden or 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
class DirectoryObserver { | |
deinit { | |
dispatch_source_cancel(source) | |
close(fileDescriptor) | |
} | |
init(URL: NSURL, block: dispatch_block_t) { |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
/*Assert methods*/ | |
class RangeAsserter{ | |
static func equals(_ a: IRange, _ b:IRange) -> Bool { | |
return a.start == b.start && a.end == b.end | |
} | |
} | |
/*Parser methods*/ | |
class RangeParser{ | |
static func length(_ range:IRange) -> Int { |
This file contains hidden or 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 | |
/*Range*/ | |
let a:Range<Int> = 1..<3 | |
print(type(of:a))//Range<Int> | |
a.upperBound//3 | |
/*ClosedRange*/ | |
let b:ClosedRange<Int> = 1...3 | |
print(type(of:b))//ClosedRange<Int> |
This file contains hidden or 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 | |
/** | |
* EXAMPLE: Range(start:2,end:6).count//4 | |
*/ | |
extension Range { | |
/** | |
* EXAMPLE: Range<Int>(0,3).numOfIndecies()//4 -> because [0,1,2,3].count// 4 | |
* NOTE: only works with Range<Int> for now | |
*/ | |
init(_ start:Bound,_ end:Bound){/*Conveninence initializer*/ |
This file contains hidden or 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) |