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
#! /usr/bin/swift | |
import ScriptingBridge | |
@objc protocol iTunesTrack { | |
optional var name: String {get} | |
optional var album: String {get} | |
} | |
@objc protocol iTunesApplication { |
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
// The Swift Programming Language book from Apple states the following: | |
// | |
// Swift automatically provides shorthand argument names to inline closures, | |
// which can be used to refer to the values of the closure’s arguments by the | |
// names $0, $1, $2, and so on. | |
// In Xcode 6.1 and 6.2b1, it appears that this is only true IF the last argument | |
// is referenced using shorthand syntax somewhere in the closure body. See below | |
// for details. |
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
protocol FooProtocol { | |
func blah() | |
} | |
struct Foo : FooProtocol { | |
func blah() {} | |
} |
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
# Drop this into your ~/.gitconfig | |
[alias] | |
delete-merged = !bash -c '\ | |
REMOTE=$1 && \ | |
REMOTE=${REMOTE:="origin"} && \ | |
echo "Fetching $REMOTE" && \ | |
git fetch $REMOTE --prune && \ | |
git branch -vv | grep "gone]" | awk \"{ print \\$1 }\" | xargs git branch -d' - | |
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 | |
func curry<A, B, C> ( f: (A, B) -> C ) -> (A -> B -> C) { | |
return { x in | |
return { y in | |
return f(x, y) | |
} | |
} | |
} |
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 Top { | |
let x: Int | |
init() { x = 3; println("Top.init") } | |
} | |
class Bottom: Top { | |
var z: String | |
// This doesn't call `super.init`, but Top.init still runs. Why? | |
init(dummy: Bool) { z = "hi" } |
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/Foundation.h> | |
// This is pretty simple, right? | |
typedef void(^SampleBlock)(NSString *str); |
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
// Usage: echo "these are some words" | words | |
// Output: | |
// these | |
// are | |
// some | |
// words | |
import Foundation | |
import Swift |
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 MyClass: NSObject { | |
var loggingProperty: String { | |
let selector = #selector(MyClass.loggingProperty) // error: instance member 'loggingProperty' cannot be used on type 'MyClass' | |
print("accessing", selector) | |
return "Hello" | |
} | |
} |
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
// ObjC | |
+ (id)modelOfClass:(Class)modelClass fromJSONDictionary:(NSDictionary *)JSONDictionary; // DEPRECATED | |
+ (id)modelOfClass:(Class)modelClass fromJSONDictionary:(NSDictionary *)JSONDictionary error:(NSError **)error; |