5 // Created by Hori,Masaki on 2017/01/02.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 private var pShipStatusContext: Int = 0
13 final class SuppliesView: NSControl {
15 private let observeKeys = [ #keyPath(Ship.fuel),
16 #keyPath(Ship.maxFuel),
18 #keyPath(Ship.maxBull)]
19 private let suppliesCell: SuppliesCell
21 override init(frame: NSRect) {
23 suppliesCell = SuppliesCell()
25 super.init(frame: frame)
27 self.cell = suppliesCell
30 required init?(coder: NSCoder) {
32 suppliesCell = SuppliesCell()
34 super.init(coder: coder)
36 self.cell = suppliesCell
43 suppliesCell.shipStatus?.removeObserver(self, forKeyPath: $0)
47 @objc var shipStatus: Ship? {
49 get { return suppliesCell.shipStatus }
53 suppliesCell.shipStatus?.removeObserver(self, forKeyPath: $0)
55 suppliesCell.shipStatus = newValue
58 suppliesCell.shipStatus?.addObserver(self, forKeyPath: $0, context: &pShipStatusContext)
64 override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
66 if context == &pShipStatusContext {
73 super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)