Author: Chris Lattner
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
struct Bar { | |
init<T : LosslessStringConvertible>(_ f: T) {} | |
init<T>(anything: T) {} | |
} | |
let b = Bar(UnicodeScalar(4)) |
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 test(closure: () -> Void) -> () -> () { | |
let localClosure : @noescape () -> Void = { closure() } | |
localClosure() | |
return localClosure // Invalid conversion from non-escaping function of type () -> Void to potentially escaping function type () -> () | |
} |
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 test(closure: () -> Void) { | |
let localClosure : @noescape () -> Void = { closure() } | |
localClosure() | |
} |
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 Foo {} | |
class Bar : Foo {} | |
class Baz : Foo {} | |
// if you remove the Foo type annotation, (bar, baz) is (Bar, Baz) will return true, | |
// as the compiler can statically check the type. | |
let bar : Foo = Bar() | |
let baz : Foo = Baz() | |
print((bar, baz) is (Bar, Baz)) // false |
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 Bar { | |
let id : Int | |
init(id: Int) { self.id = id } | |
} | |
class Foo { | |
var bar : Bar | |
init(bar: Bar) { self.bar = bar} | |
func printBar() { |
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 | |
import QuartzCore | |
func benchmark(repeatCount: Int = 1, name: String = "closure", closure: () -> Void) { | |
let d = CACurrentMediaTime() | |
for _ in 0..<repeatCount { | |
closure() | |
} | |
let d1 = CACurrentMediaTime()-d | |
print("Benchmark of \(name) took \(d1) seconds") |
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 | |
struct ConstraintInfo { | |
var attribute: NSLayoutAttribute = .left | |
var secondAttribute: NSLayoutAttribute = .notAnAttribute | |
var constant: CGFloat = 0 | |
var identifier: String? | |
var relation: NSLayoutRelation = .equal | |
} |