Skip to content

Instantly share code, notes, and snippets.

View MartinJNash's full-sized avatar

Martin Nash MartinJNash

View GitHub Profile
@MartinJNash
MartinJNash / ArrayByTwo.swift
Created September 12, 2014 17:50
Get adjacent pairs in an array.
extension Array {
func twoAtATime(block: ((f: T, s: T))->()) {
var _first: T? = nil
var _second: T? = nil
for e:T in self {
_first = _second
_second = e
if _first != nil && _second != nil {
@MartinJNash
MartinJNash / DateStringMethods.swift
Last active August 29, 2015 14:04
Swift Date & String Methods
extension NSString {
func toDateWithFormatter(dateFormatter: NSDateFormatter) -> NSDate? {
return dateFormatter.dateFromString(self)
}
}
@MartinJNash
MartinJNash / SwiftRubyCrowbarOperator.swift
Last active December 14, 2015 17:30
Ruby Crowbar Operator in Swift
import Cocoa
infix operator ||= {}
func ||= <T> (inout value: T?, newValue: @autoclosure () -> T) -> T {
if value == nil {
value = newValue()
}
return value!
@MartinJNash
MartinJNash / gist:3ce49f4ae48190bc1fe1
Created June 7, 2014 19:07
Swift prepare for segue
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!)
{
if let vc = segue.destinationViewController as? CreateNoteViewController {
println("Create Note VC")
}
if let vc = segue.destinationViewController as? SingleNoteViewController {
println("Show single note")
}
}
@MartinJNash
MartinJNash / gist:e2bb27937711f350aa44
Created June 7, 2014 00:43
Class name to string in Swift
class Person {
class func classString() -> String {
return NSStringFromClass(self)
}
}
Person.classString() // "_TtC11lldb_expr_06Person"
ALAssetRepresentation *rep = [asset defaultRepresentation];
NSDictionary *dict = [rep metadata];
NSString *xmp = dict[@"AdjustmentXMP"];
NSData *xmpData = [xmp dataUsingEncoding:NSUTF8StringEncoding];
NSError *e = nil;
NSArray *filters = [CIFilter filterArrayFromSerializedXMP:xmpData inputImageExtent:CGRectZero error:&e];
CIFilter *filter = [filters firstObject];
CIImage *image =[CIImage imageWithCGImage: [rep fullScreenImage]];
[filter setValue:image forKey:kCIInputImageKey];