If you’ve ever coded for iOS you’ll most likely be familiar with the UIView animateWithDuration function. Wouldn’t it be great if there would be an OSX equivalent? Well, there sure is, just type the following: NSAnimationContext.runAnimationGroup({_in //Indicate the duration of the animation …
Category Archives: development
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: …
Continue reading “Synchronizing Main and Background Core Data Threads (Swift 3)”
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 …
Continue reading “Are we (NSViewController view) the First Responder?”
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: …
Continue reading “Undo functionality in Core Data (Swift 3)”
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 …
Continue reading “Sorting Multi Dimensional Array (Swift 3)”
Dates & Components in Swift 3.0
The way we work with dates has changed in Swift 3, the change makes it’s way simpler then before. Let’s look at an example: //CreateDateFromComponents (1st January 2017) var newDate = Date() let newDateComponents = DateComponents(calendar: Calendar.current, timeZone: nil, era: nil, year: 2017, …
Testing launch experience for a Mac app
In iOS it’s quite easy, you just delete the app and all of it’s data is removed as well. But how do you do it in OSX? Well, you should remove: ~/Library/Application Support/<YOUR OSX APP BUNDLE NAME>/ for example, by default should be: ~/Library/Application Support/com.yourcompany.yourapp/ And this is it! I suggest you do a Project …
Scheduled notifications in macOS
Notifications are a very useful addition to macOS applications, when done right can help inmensly. Here’s how you create scheduled and immediate notifications. Let’s start with the immediate ones: func triggerNotification() -> Void { let notification = NSUserNotification() notification.title = “titleOfNotification” notification.informativeText = “whateverTextYou WantToAdd” notification.soundName = …
Copy one or multiple NSTableView rows, Swift
So here’s a simple yet tricky one: you’ve created your NSTableView but now you would like to allow a user to copy to the clipboard one, or a couple of rows. How do you do it? 1. Implement the function copy (func copy(sender: AnyObject?){}), do not confuse with the method for duplicating an object. 2. Get the …
Continue reading “Copy one or multiple NSTableView rows, Swift”
Easy Core Data CSV Exporter in Swift
A new app I’m working on has a Core Data back end and I wanted to implement a quick way to export all the entities into a CSV file and dump it into the Desktop. Here are the snippets to do it: 1. Make sure you get the NSObjects you want to export (in this case …