Skip to content

Instantly share code, notes, and snippets.

@corbinstreehouse
Created April 9, 2019 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corbinstreehouse/d5601d0f543999c66c1a8111ae5a5ec1 to your computer and use it in GitHub Desktop.
Save corbinstreehouse/d5601d0f543999c66c1a8111ae5a5ec1 to your computer and use it in GitHub Desktop.
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)
}
return result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment