This file contains 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 | |
fileprivate enum StdStream { | |
case out | |
case err | |
fileprivate var fileDescriptor: FileDescriptor { | |
switch self { | |
case .out: return FileDescriptor(STDOUT_FILENO, "stdout") | |
case .err: return FileDescriptor(STDERR_FILENO, "stderr") |
This file contains 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 a hideous hack for 10.11 where constraints are applied for detached view and the entire | |
// toolset panel looks like a huge cock… | |
if #available(macOS 10.13, *) { | |
} else if self.instructionView.isHidden && self.instructionView.superview != nil { | |
self.stackView.removeView(self.instructionView) | |
} else if !self.instructionView.isHidden && self.instructionView.superview == nil { | |
self.stackView.insertView(self.instructionView, at: 0, in: .center) | |
} |
This file contains 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
private func exclude(paths: [String], at basePath: String) -> [String] { | |
let slash = CharacterSet(charactersIn: "/") | |
let baseURL = URL(fileURLWithPath: basePath, isDirectory: true) | |
var exclusions = try! FileManager.default.contentsOfDirectory(atPath: basePath).sorted() | |
var inclusions = paths | |
// Cleanup paths removing and expanding `/.`, `/..`, etc. | |
inclusions = inclusions.reduce(into: [], { inclusions, inclusion in | |
let path = URL(fileURLWithPath: inclusion, relativeTo: baseURL).standardized.relativePath.trimmingCharacters(in: slash) | |
if !path.isEmpty { inclusions.append(path) } |
This file contains 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 Slang | |
let source: String = "import Foundation; class Foo { let bar = 1 }" | |
let file: File = File(source) | |
let disassembly: Disassembly = try! Disassembly(file) | |
var edits: [Edit] = [] | |
// Change "Foundation" identifier to "AppKit". | |
edits.append(Edit(disassembly.query.syntax.first(of: .identifier).select(where: { $0.contents == "Foundation" }).one!, "AppKit")) | |
// Change "class" keyword to "struct". |
This file contains 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 AppKit | |
import Metal | |
import QuartzCore | |
let view = NSView(frame: CGRect(x: 0, y: 0, width: 600, height: 400)) | |
let circle = NSView(frame: CGRect(x: 0, y: 0, width: 50, height: 50)) | |
circle.wantsLayer = true | |
circle.layer?.backgroundColor = NSColor.red.cgColor | |
circle.layer?.cornerRadius = 25 |
This file contains 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
let fooOne: Foo = Foo() | |
let fooTwo: Foo = Foo() | |
fooOne.reactive.signal.bar.observeValues({ Swift.print($0) }) | |
fooOne.reactive.bind.bar <~ fooTwo.reactive.signal.bar | |
fooOne.bar = "Such b-a-r!" | |
fooTwo.bar = "Very BAR!" |
This file contains 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: ReactiveExtensionsProvider { | |
let pipe = Signal<String, NoError>.pipe() | |
var bar: String = "Such bar!" { | |
didSet { self.pipe.input.send(value: self.bar) } | |
} | |
} | |
extension Reactive.Binds where Base: Foo { | |
var bar: BindingTarget<String> { | |
return self.reactive.makeBindingTarget({ $0.bar = $1 }) |
This file contains 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 Reactive { | |
/// A proxy which holds reactive binding target extensions of `Base`. | |
struct Binds<Base> { | |
fileprivate init(_ base: Base) { self.base = base } | |
let base: Base | |
} | |
var bind: Binds<Base> { return Binds(self.base) } |
This file contains 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 <AVFoundation/AVFoundation.h> | |
@interface MLWAsyncAVPlayer : AVPlayer | |
@end |
This file contains 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> | |
#import <MyProject/MyProject-Swift.h> | |
// This was a more concise solution in Swift 4.2 and earlier. If you try this with Swift 5 you'd get "Swift class | |
// extensions and categories on Swift classes are not allowed to have +load methods" runtime error. | |
// @implementation Foo (private) | |
// + (void)load { [self swiftyLoad]; } | |
// + (void)initialize { [self swiftyInitialize]; } | |
// @end |
NewerOlder