Skip to content

Instantly share code, notes, and snippets.

View corbinstreehouse's full-sized avatar

corbin dunn corbinstreehouse

View GitHub Profile
@corbinstreehouse
corbinstreehouse / CustomTextFieldCell.swift
Created April 9, 2019 15:39
Save the previous color of an NSTextFieldCell when selected
// Custom text colors don't automagically invert.
class TableViewTextFieldCell: NSTextFieldCell {
private var previousTextColor: NSColor?
override var backgroundStyle: NSView.BackgroundStyle {
get {
return super.backgroundStyle
}
set(newBackgroundStyle) {
@corbinstreehouse
corbinstreehouse / TableViewTextFieldCell.swift
Created April 9, 2019 14:43
Implementing [NSCell copyWithZone:] in Swift
// Swift 3.0
class TableViewTextFieldCell: NSTextFieldCell {
private var previousTextColor: NSColor?
override func copy(with zone: NSZone? = nil) -> Any {
let result: TableViewTextFieldCell = super .copy(with: zone) as! TableViewTextFieldCell
if let previousTextColor = result.previousTextColor {
// Add the needed retain now
let _ = Unmanaged<NSColor>.passRetained(previousTextColor)