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
public struct DefaultDictionary<Key : Hashable, Value>: CollectionType { | |
private var _storage: [Key: Value] | |
private var _defaultValue: () -> Value | |
public typealias Element = (Key, Value) | |
public typealias Index = DictionaryIndex<Key, Value> | |
public var startIndex: Index { | |
return _storage.startIndex |
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
func f<T, U>(x: T.Type, _ y: U) -> Bool { | |
return y is T | |
} | |
func g<T, U>(x: T, _ y: U) -> Bool { | |
return y is T | |
} | |
protocol P {} | |
class B: P {} |
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
# run this in the swift source code folder to get a list of radars | |
for i in $(grep -hor -E 'rdar://problem/[0-9]+' stdlib lib | sed 's/rdar:\/\/problem\///'); do if [[ ! -z $(curl -s "http://www.openradar.me/$i" | grep 'Tell us more!') ]]; then echo rdar://problem/$i; fi; done |
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
// this is almost good, if only Swift allows specifying precedence for pre/postfix operators. | |
struct Dollar {} | |
let $ = Dollar() | |
struct BInt: IntegerLiteralConvertible { | |
let bool: Bool | |
let int: UInt | |
func relativeTo(total: Int) -> Int { | |
return bool ? total - Int(int) : Int(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
// Experimental: | |
// '%' replaces the more ideal '$' | |
// where a open ended range is in the design, `nil` is used its place | |
// force casting between Index.Distance and 'Int' | |
// only on CollectionType, but a version for string is not hard to do | |
public struct Offset { let value: Int } | |
prefix operator %+ {} | |
prefix operator %- {} |
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 | |
var before = NSDate() | |
var after = NSDate() | |
var duration: NSTimeInterval = 0 | |
var a = Set(Array(1..<9999).sort {_, _ in arc4random() % 2 == 0}) | |
(1...10000).forEach { _ in | |
var b = a | |
before = NSDate() |
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 | |
let smallSet = Set(Array(1..<999).sort {_, _ in arc4random() % 2 == 0}) | |
let largeSet = Set(Array(1..<99999).sort {_, _ in arc4random() % 2 == 0}) | |
var _count = 999999 | |
let unique: () -> Int = { _count += 1; return _count } | |
var before = NSDate() | |
var after = NSDate() |
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
extension Int { | |
func asUpperBoundForRandom() -> Int { | |
return Int(arc4random_uniform(UInt32(self))) | |
} | |
func asLengthForRandomAlphanumeric() -> String { | |
let alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".characters | |
var chars: [Character] = [] | |
for _ in 1...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
SDKPATH = $(shell xcrun --show-sdk-path --sdk macosx) | |
CBRIDGEHEADER = bridge.h | |
TARGETS := cat | |
.PHONY : all $(TARGETS) | |
all: $(TARGETS) | |
$(TARGETS): | |
swiftc -sdk $(SDKPATH) [email protected] -import-objc-header $(CBRIDGEHEADER) -o $@ |
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
// Swift 2 Beta 2 to the rescue! | |
protocol A { | |
var b: B { get set } | |
} | |
protocol B { | |
func handle() | |
} | |
extension B { |