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
// | |
// SMBond+Position.swift | |
// SMChemSketchSwiftModel | |
// | |
// Created by Stephan Michels on 09.01.17. | |
// Copyright © 2017 Stephan Michels. All rights reserved. | |
// | |
import Foundation | |
import SMGraphics |
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 SwiftUI | |
extension CGRect { | |
fileprivate func point(anchor: UnitPoint) -> CGPoint { | |
var point = self.origin | |
point.x += self.size.width * anchor.x | |
#if os(macOS) | |
point.y += self.size.height * (1 - anchor.y) | |
#else | |
point.y += self.size.height * anchor.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 Holder<T: AnyObject> { | |
var value: T? = nil | |
init() { | |
self.value = nil | |
} | |
init(_ value: T) { | |
self.value = 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 | |
public func with<T>(_ item: T, update: (inout T) throws -> Void) rethrows -> T { | |
var this = item; try update(&this); return this | |
} | |
let path = with(CGMutablePath()) { // <--- Bad Access | |
$0.move(to: CGPoint(x: 0, y: 0)) | |
$0.addLine(to: CGPoint(x: 100, y: 100)) | |
} |
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 | |
extension CGPoint { | |
public func length() -> CGFloat { | |
return hypot(self.x, self.y) | |
} | |
} | |
infix operator ⋅ { associativity left precedence 140 } |
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 | |
public extension CGPath { | |
public convenience init(roundedRect rect: CGRect, corner: CGSize) { | |
self.init(roundedRect: rect, cornerWidth: corner.width, cornerHeight: corner.height, transform: nil) | |
} | |
} |
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 | |
class Object1: Protocol1, CustomStringConvertible { | |
var description: String { return "<\(String(self.dynamicType)):\(unsafeAddressOf(self))>" } | |
} | |
protocol Protocol1: class { | |
} | |
let object1 = Object1() |
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 Copyable { | |
func copy() -> Self | |
} | |
class Class1: Copyable { | |
var variable1: String | |
init(variable1: String) { | |
self.variable1 = variable1 | |
} |
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 | |
let window = NSWindow(contentRect: NSRect(origin: .zero, size: NSSize(width: 500.0, height: 500.0)), styleMask: 0, backing: .Buffered, defer: false) | |
var responder = window.firstResponder | |
var responderIndex = 1 | |
repeat { | |
print("Responder: \(responder)") |
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 | |
class TestObject { | |
init() { | |
print("Init \(self)") | |
} | |
deinit { | |
print("Deinit \(self)") | |
} |
NewerOlder