.../Source/Extensions/NSTableView+getRowView.swift
Line | Count | Source (jump to first uncovered line) |
1 | | // |
2 | | // NSTableView+getRowView.swift |
3 | | // CutBox |
4 | | // |
5 | | // Created by Jason Milkins on 10/5/18. |
6 | | // Copyright © 2018-2023 ocodo. All rights reserved. |
7 | | // |
8 | | |
9 | | import Cocoa |
10 | | |
11 | | extension NSTableView { |
12 | 151 | func getRowView<T: NSView>() -> T { |
13 | 151 | let identifier = NSUserInterfaceItemIdentifier( |
14 | 151 | rawValue: "\(T.self)") |
15 | 151 | |
16 | 151 | var dequeuedRowView: T? = self.makeView( |
17 | 151 | withIdentifier: identifier, owner: self |
18 | 151 | ) as? T |
19 | 151 | |
20 | 151 | if dequeuedRowView == nil { |
21 | 151 | dequeuedRowView = T.fromNib() |
22 | 151 | dequeuedRowView?.identifier = identifier |
23 | 151 | } |
24 | 151 | |
25 | 151 | guard let rowView: T = dequeuedRowView |
26 | 151 | else { fatalError("Unable to get a \(T.self)") } |
27 | 151 | |
28 | 151 | return rowView |
29 | 151 | } |
30 | | } |