aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS/NSTableView+Reuse.swift
blob: 3a36b6a31887ee33949c5d42d469100d34cf325b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// SPDX-License-Identifier: MIT
// Copyright © 2018 WireGuard LLC. All Rights Reserved.

import Cocoa

extension NSTableView {
    func dequeueReusableCell<T: NSView>() -> T {
        let identifier = NSUserInterfaceItemIdentifier(NSStringFromClass(T.self))
        if let cellView = makeView(withIdentifier: identifier, owner: self) {
            //swiftlint:disable:next force_cast
            return cellView as! T
        }
        let cellView = T()
        cellView.identifier = identifier
        return cellView
    }
}