OSDN Git Service

Doutakuを導入
[kcd/KCD.git] / KCD / ScreenshotInformation.swift
index ab63478..248a13f 100644 (file)
@@ -10,23 +10,29 @@ import Cocoa
 
 final class ScreenshotModel: NSObject {
     
-    dynamic var screenshots: [ScreenshotInformation] = []
-    dynamic var sortDescriptors: [NSSortDescriptor]?
-    dynamic var selectedIndexes: IndexSet?
-    dynamic var filterPredicate: NSPredicate?
+    @objc dynamic var screenshots: [ScreenshotInformation] = []
+    @objc dynamic var sortDescriptors: [NSSortDescriptor]?
+    @objc dynamic var selectedIndexes: IndexSet?
+    @objc dynamic var filterPredicate: NSPredicate?
 }
 
 final class ScreenshotInformation: NSObject, NSCoding {
     
-    let url: URL
+    @objc let url: URL
     
-    var creationDate: Date? {
+    @objc lazy var image: NSImage? = {
+        
+        guard let image = NSImage(contentsOf: url) else { return Logger.shared.log("Can not load image", value: nil) }
+        return image
+    }()
+    
+    @objc var creationDate: Date? {
         
         let attr = try? url.resourceValues(forKeys: [.creationDateKey])
         
         return attr?.creationDate
     }
-    var tags: [String]? {
+    @objc var tags: [String]? {
         
         get {
             let attr = try? url.resourceValues(forKeys: [.tagNamesKey])
@@ -73,8 +79,7 @@ final class ScreenshotInformation: NSObject, NSCoding {
     
     required convenience init?(coder aDecoder: NSCoder) {
         
-        guard let u = aDecoder.decodeObject(forKey: CodingKey.url) as? URL
-            else { return nil }
+        guard let u = aDecoder.decodeObject(forKey: CodingKey.url) as? URL else { return nil }
         
         self.init(url: u)
     }
@@ -85,7 +90,7 @@ final class ScreenshotInformation: NSObject, NSCoding {
     }
 }
 
-fileprivate let dateFormatter: DateFormatter = {
+private let dateFormatter: DateFormatter = {
     
     let f = DateFormatter()
     f.dateStyle = .short
@@ -97,16 +102,15 @@ fileprivate let dateFormatter: DateFormatter = {
 
 extension ScreenshotInformation {
     
-    var name: String? {
+    @objc var name: String? {
         
         let attr = try? url.resourceValues(forKeys: [.localizedNameKey])
         
         return attr?.localizedName
     }
     
-    var creationDateString: String? {
+    @objc var creationDateString: String? {
         
-        return creationDate
-            .map { dateFormatter.string(from: $0) }
+        return creationDate.map(dateFormatter.string(from:))
     }
 }