I hereby claim:
- I am westerlund on github.
- I am westerlund (https://keybase.io/westerlund) on keybase.
- I have a public key whose fingerprint is 3769 3506 050F 206C 8F5E 28C5 84AC A96F 3E1A DC6F
To claim this, I am signing this object:
// | |
// NSAttributedString+sizeInWidth.h | |
// | |
// Created by Simon Westerlund on 13/03/14. | |
// Copyright (c) 2014 Simon Westerlund. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSAttributedString (sizeInWidth) |
I hereby claim:
To claim this, I am signing this object:
----BEGIN PGP MESSAGE----- | |
Version: GnuPG/MacGPG2 v2.0.22 (Darwin) | |
Comment: GPGTools - https://gpgtools.org | |
hQIMA9UKSPis5L98AQ//Q7dblsb52hEkAPbPoBTSeDAwYMI72fsbmM2cZpkT0hnw | |
whm7xcYBlttjAVctWc/lcte9mSvJMq15V/MkWzFC6haW/fW8pOlgPtKkySqSCFd0 | |
R3Hf+j2cQyFafkTxx0leffRoorqA8w90eIPwA+3YMYpwXGMIA+Dx5AMd1Q73YeG0 | |
0GXb6RnLvVJzLsFpJAw2WYpij+IkQibU0JPWIFuOZPkrXXcuPrVFGpkKgS4QfACP | |
4CAiDB3SG5svrsMGQSErLHEueP2hGgUGHGJA1VYw+RZ4w5ofmnDkjYCFHBn1Lq/r |
// github doesn't support .playground files, just copy this in a playground to quick run it | |
class AsyncThing { | |
// set up a optional callback variable that takes a closure with a return of Void | |
// that closure takes another (non-optional) closure named "done" which returns Void | |
var callback:((done: () -> Void) -> Void)? | |
// just a dummy method to execute the blocks | |
func run() { | |
// set up a constant block, this is just for readability |
// | |
// RBResizer.swift | |
// Locker | |
// | |
// Created by Hampton Catlin on 6/20/14. | |
// Copyright (c) 2014 rarebit. All rights reserved. | |
// | |
import UIKit |
func createGIF(with images: [UIImage], loopCount: Int = 0, frameDelay: Double, callback: (data: NSData?, error: NSError?) -> ()) { | |
let fileProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFLoopCount as String: loopCount]] | |
let frameProperties = [kCGImagePropertyGIFDictionary as String: [kCGImagePropertyGIFDelayTime as String: frameDelay]] | |
let documentsDirectory = NSTemporaryDirectory() | |
let url = NSURL(fileURLWithPath: documentsDirectory)?.URLByAppendingPathComponent("animated.gif") | |
if let url = url { | |
let destination = CGImageDestinationCreateWithURL(url, kUTTypeGIF, UInt(images.count), nil) | |
CGImageDestinationSetProperties(destination, fileProperties) |
class SomeClass { | |
var a: String? | |
var b: [Int]? | |
private func _u(named: String, value: AnyObject?, set: Bool) -> AnyObject? { | |
switch named { | |
case "a": | |
if set { | |
a = value as? String |
func dispatch(#after: NSTimeInterval, queue: dispatch_queue_t = dispatch_get_main_queue(), #closure: dispatch_block_t) { | |
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(Double(after) * Double(NSEC_PER_SEC))) | |
dispatch_after(time, dispatch_get_main_queue(), closure) | |
} | |
func dispatch(#after: NSTimeInterval, closure: dispatch_block_t) { | |
dispatch(after: after, closure: closure) | |
} | |
dispatch(after: 0.5, { () -> Void in |
extension NSImage { | |
func writeToFile(file: String, atomically: Bool, usingType type: NSBitmapImageFileType) -> Bool { | |
let properties = [NSImageCompressionFactor: 1.0] | |
guard | |
let imageData = TIFFRepresentation, | |
imageRep = NSBitmapImageRep(data: imageData), | |
fileData = imageRep.representationUsingType(type, properties: properties) else { | |
return false | |
} | |
return fileData.writeToFile(file, atomically: atomically) |
//: Playground - noun: a place where people can play | |
import Cocoa | |
let bounds = CGRectMake(0, 0, 100, 100); | |
func DrawImageInCGContext(size: CGSize, drawFunc: (context: CGContextRef, rect: CGRect) -> Void) -> NSImage? { | |
let colorSpace = CGColorSpaceCreateDeviceRGB() | |
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedLast.rawValue) | |
if let context = CGBitmapContextCreate( |