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 […]
Mar 29 2020
Saving a font to UserDefaults
(Here using macOS 13, Xcode 10, Swift 4.2, but NSFontDescriptor also exists on iOS, just substitute UIFont). The recommended way of saving a font is not to do it (a bit flippant, sorry) – but in WWDC session 223 from 2013 (Using Fonts with TextKit), the recommendation is specifically to a) not cherry-pick attributes (in […]
By Extelligent Cocoa • Interface, Wiki • • Tags: NSFont, NSFontDescriptor, NSTextField, UserDefaults