class BridgeViewController: NSViewController {
- @IBOutlet var arrayController: NSArrayController!
+ @IBOutlet private(set) var arrayController: NSArrayController!
deinit {
- [.contentArray, .sortDescriptors, .selectionIndexes, .filterPredicate]
- .forEach { arrayController.unbind($0) }
+ arrayController.unbind(.contentArray)
+ arrayController.unbind(.sortDescriptors)
+ arrayController.unbind(.selectionIndexes)
+ arrayController.unbind(.filterPredicate)
}
override var representedObject: Any? {
didSet {
- guard let representedObject = representedObject else { return }
- [
- (.contentArray, #keyPath(ScreenshotModel.screenshots)),
- (.sortDescriptors, #keyPath(ScreenshotModel.sortDescriptors)),
- (.selectionIndexes, #keyPath(ScreenshotModel.selectedIndexes)),
- (.filterPredicate, #keyPath(ScreenshotModel.filterPredicate))
- ]
- .forEach {
- arrayController.bind($0.0, to: representedObject, withKeyPath: $0.1, options: nil)
+ guard let representedObject = representedObject as? ScreenshotModel else {
+
+ return
}
+
+ arrayController.bind(.contentArray, to: representedObject, withKeyPath: #keyPath(ScreenshotModel.screenshots))
+ arrayController.bind(.sortDescriptors, to: representedObject, withKeyPath: #keyPath(ScreenshotModel.sortDescriptors))
+ arrayController.bind(.selectionIndexes, to: representedObject, withKeyPath: #keyPath(ScreenshotModel.selectedIndexes))
+ arrayController.bind(.filterPredicate, to: representedObject, withKeyPath: #keyPath(ScreenshotModel.filterPredicate))
}
}
private var tagString: String? {
let tag = LocalizedStrings.tweetTag.string
- if tag == "" { return "" }
+ if tag == "" {
+
+ return ""
+ }
return "#\(tag)"
}
@IBAction func share(_ sender: AnyObject?) {
- guard let view = sender as? NSView else { return }
+ guard let view = sender as? NSView else {
+
+ return
+ }
let picker = NSSharingServicePicker(items: itemsForShareingServicePicker())
picker.delegate = self
private func itemsForShareingServicePicker() -> [AnyObject] {
- guard let informations = arrayController.selectedObjects as? [ScreenshotInformation] else { return [] }
+ guard let informations = arrayController.selectedObjects as? [ScreenshotInformation] else {
+
+ return []
+ }
- let images: [NSImage] = informations.flatMap { NSImage(contentsOf: $0.url) }
- if !appendKanColleTag { return images }
+ let images: [NSImage] = informations.compactMap { NSImage(contentsOf: $0.url) }
+ if !appendKanColleTag {
+
+ return images
+ }
if let tag = tagString {
return ["\n\(tag)" as AnyObject] + images