2 // ScreenshotInformation.swift
5 // Created by Hori,Masaki on 2017/01/28.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 class ScreenshotModel: NSObject {
12 dynamic var screenshots: [ScreenshotInformation] = []
13 dynamic var sortDescriptors: [NSSortDescriptor]?
14 dynamic var selectedIndexes: IndexSet?
15 dynamic var filterPredicate: NSPredicate?
18 class ScreenshotInformation: NSObject, NSCoding {
20 var creationDate: Date? {
21 let attr = try? url.resourceValues(forKeys: [.creationDateKey])
22 return attr?.creationDate
26 let attr = try? url.resourceValues(forKeys: [.tagNamesKey])
30 let url = self.url as NSURL
32 if let array = newValue {
33 try url.setResourceValue(array as NSArray, forKey: .tagNamesKey)
35 try url.setResourceValue([] as NSArray, forKey: .tagNamesKey)
38 print("Can not set tagNames")
42 private(set) var version: Int
44 init(url: URL, version: Int = 0) {
46 self.version = version
50 func incrementVersion() { version = version + 1 }
54 static let url = "Url"
55 static let version = "Version"
57 required convenience init?(coder aDecoder: NSCoder) {
58 guard let u = aDecoder.decodeObject(forKey: CodingKey.url) as? URL
62 func encode(with aCoder: NSCoder) {
63 aCoder.encode(url, forKey: CodingKey.url)
67 fileprivate let dateFormatter: DateFormatter = {
68 let f = DateFormatter()
71 f.doesRelativeDateFormatting = true
75 extension ScreenshotInformation {
77 let attr = try? url.resourceValues(forKeys: [.localizedNameKey])
78 return attr?.localizedName
80 var creationDateString: String? {
82 .map { dateFormatter.string(from: $0) }