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
--indent 4 | |
--self insert | |
--extensionacl on-declarations | |
--modifierorder required,dynamic,override,public,private,private(set),lazy | |
--ranges no-space | |
--patternlet inline | |
--disable consecutiveBlankLines, strongOutlets, blankLinesAroundMark, unusedArguments | |
--disable spaceInsideComments, redundantParens, andOperator, consecutiveSpaces, redundantReturn | |
--disable indent, redundantNilInit, redundantType, redundantObjc, enumNamespaces |
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 SourceListTableCellView: NSTableCellView { | |
override var draggingImageComponents: [NSDraggingImageComponent] { | |
let components = super.draggingImageComponents | |
guard | |
self.backgroundStyle == .emphasized, //emphasized = selected | |
let textField = self.textField, | |
let newStyle = textField.attributedStringValue.mutableCopy() as? NSMutableAttributedString, | |
let labelIndex = components.firstIndex(where: { $0.key == .label }) | |
else { | |
return components |
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 ExtendableFilePromiseProvider: NSFilePromiseProvider { | |
var additionalItems: [NSPasteboard.PasteboardType: Any] = [:] | |
override func writableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] { | |
var types = super.writableTypes(for: pasteboard) | |
if self.additionalItems.count > 0 { | |
types.append(contentsOf: self.additionalItems.keys) | |
} | |
return types | |
} |
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 MyOutlineDelegate: NSObject, NSOutlineViewDelegate { | |
//The cell we'll use for calculating sizes, should be the same cell used in the outline | |
lazy var sizingCell: MyCell = { | |
let cell = MyCell(frame: .zero) | |
cell.translatesAutoresizingMaskIntoConstraints = false | |
return cell | |
}() | |
lazy var sizingCellWidthAnchor: NSLayoutConstraint = { | |
return self.sizingCell.widthAnchor.constraint(equalToConstant: 1000) |
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 Foo { | |
var string = "test" | |
var optionalString: String? | |
} | |
let foo = Foo() | |
foo[keyPath: \.string] == nil //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 Foo<T> { | |
struct Bar { | |
let handler: (T) -> Void | |
} | |
var bars: [Bar] | |
} |
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 Test { | |
var foo: String { get set } | |
func updateFoo() | |
} | |
extension Test where Self: NSObject { | |
func updateFoo() { | |
self.foo = "Bar" // <- Error: Cannot assign to property: 'self' is immutable | |
} |
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 Foo: NSObject { | |
var objectID = UUID() | |
} | |
let foo = Foo() // Crashes with "error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x20)." |
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
//Obj-C | |
typedef NSString * ABCMessageField NS_STRING_ENUM; | |
extern ABCMessageField const ABCMessageFieldSubject; | |
extern ABCMessageField const ABCMessageFieldFrom; | |
//Expected Swift (according to https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html#//apple_ref/doc/uid/TP40014216-CH8-ID17) | |
struct ABCMessageField: RawRepresentable { | |
typealias RawValue = String | |
init(rawValue: RawValue) |
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
@property (assign, nonatomic) CGSize preferredMaxSize; | |
- (CGSize)intrinsicContentSize { | |
CGSize imageSize = self.image.size; | |
CGSize maxSize = self.preferredMaxSize; | |
if (imageSize.height > maxSize.height) { | |
imageSize.width *= maxSize.height / imageSize.height; | |
imageSize.height = maxSize.height; | |
} |
NewerOlder