Jan 13 2019
NSDocumentController basics
Xcode 10, macOS 13.5, Swift 4.2 Without wanting to delve too deep into the NSDocumentController class: It’s part of the document architecture, and if your app uses more than one NSDocument subclass, you will need to override the following method: override func makeUntitledDocument(ofType typeName: String) throws -> NSDocument { switch typeName { case “ThingB”: return […]
Jan 28 2019
Get the modification (or creation) date of a file
Xcode 10, Swift 4.2, macOS 10.13 func fileModificationDate(url: URL) -> Date? { do { let attr = try FileManager.default.attributesOfItem(atPath: url.path) return attr[FileAttributeKey.modificationDate] as? Date } catch { return nil } } FileAttributeKey.creationDate works exactly the same; .size and .type might also be of interest. This beautiful and elegant solution comes from this Stackoverflow answer and […]
By Extelligent Cocoa • File Handling, Wiki • • Tags: FileAttributeKey, FileManager