Synchronizing Main and Background Core Data Threads (Swift 3)

Let’s say we have two different managedObjectContext (with one persistentStoreCoordinator).  The first one is used across the app for most quick fetches: var mainManagedObjectContext = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.mainQueueConcurrencyType)           mainManagedObjectContext.persistentStoreCoordinator = coordinator     And the second, running in the background, for the queries that take a long time: var backgroundManagedObjectContext = NSManagedObjectContext(concurrencyType: …

Are we (NSViewController view) the First Responder?

In some cases a class may want to know if it’s the first responder before triggering an action. For instance if several loaded View Controller classes are listening for the same notification, how can they know which one should trigger the action? Well… they should ask their view.  In this case a NSTableView class is …

Undo functionality in Core Data (Swift 3)

If you’re developing a Core Data based application for Mac, wouldn’t it be great if you could add undo support? Well, turns out that is a couple of lines away. Follow the simple steps: 1. Make sure your managedObjectContext has an undo manager, without it Core Data can’t keep track of the changes:     …

Sorting Multi Dimensional Array (Swift 3)

Hello all,  This one I’ve found specially useful when working with Core Data fetched arrays.  Let’s say that we want to sort the result of a fetch request based on the value of the field “gold”, we would therefore do the following: let dwarfGoldBags = … //Contains the result of a fetch request with one of the …