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])
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)
}
}
}
-fileprivate let dateFormatter: DateFormatter = {
+private let dateFormatter: DateFormatter = {
let f = DateFormatter()
f.dateStyle = .short
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:))
}
}