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 XCTAssertThrowsError2<T>(_ expression: () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line, _ errorHandler: (Error) -> Void = { _ in }) { | |
do { | |
_ = try expression() | |
XCTFail(message()) | |
} catch { | |
errorHandler(error) | |
} | |
} |
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 A {} | |
// foo | |
func foo<T>(_ v: T, handler: () -> Void) -> T { | |
print("regular") | |
return v | |
} | |
func foo<T>(_ v: T?, handler: () throws -> Void) rethrows -> T? { |
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
// https://bugs.swift.org/browse/SR-10906 | |
import Foundation | |
protocol ViewDataSource: class { | |
func foo<T>() -> [T] | |
} | |
class View { | |
weak var delegate: ViewDataSource? |
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 Node: CustomStringConvertible { | |
let title: String | |
var parent: Node? | |
var children: [Node] = [] { | |
didSet { | |
children.forEach({ $0.parent = self }) | |
} | |
} | |
var description: String { |
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
@discardableResult | |
public func with<T>(_ value: T, _ builder: (T) -> Void) -> T { | |
builder(value) | |
return value | |
} | |
@discardableResult | |
public func with<T>(_ value: T, _ builder: (T) throws -> Void ) rethrows -> T { | |
try builder(value) | |
return value |
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 | |
final class WindowController: NSWindowController { | |
init() { | |
let window = NSWindow() | |
window.styleMask = [.closable, .miniaturizable, .resizable, .titled] | |
super.init(window: window) | |
self.shouldCascadeWindows = false | |
window.setFrameAutosaveName(String(describing: type(of: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
import Foundation | |
public class Foo: Por { | |
public required init() {} | |
} | |
public protocol Por { | |
associatedtype As = Void | |
init(parameters: As?) throws | |
} |
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
/* | |
* Optional value is not initialized with nil, instead is initialized with 0 value | |
*/ | |
let p = UnsafeMutablePointer<UInt8?>.allocate(capacity: 0) | |
// p.initialize(repeating: nil, count: 1) | |
print("Value Type: \(type(of:p.pointee))") | |
if let value = p.pointee { |
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 | |
// Process stream | |
// http://ascii-table.com/ansi-escape-sequences-vt-100.php | |
// http://ascii-table.com/ansi-escape-sequences.php | |
public final class ANSIEscapeProcessor { | |
public func tokens(string: String) -> [Token] { | |
var tokens: [Token] = [] |
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
Load command 12 | |
cmd LC_LOAD_DYLIB | |
cmdsize 80 | |
name @executable_path/../Frameworks/libSwiftSyntax.dylib (offset 24) | |
time stamp 2 Thu Jan 1 01:00:02 1970 | |
current version 0.0.0 | |
compatibility version 0.0.0 | |
Load command 43 | |
cmd LC_RPATH | |
cmdsize 32 |