Inserting cells at the top of a UITableView with no scrolling

If you would like your table to be refreshed “ala Twitter”, with new data being added on top, here’s a quick an easy way to do it for iOS:  func updateTableViewAfterAdditionInNewArray(){         //Get new feeds and check if counts are different         let countOfAddedItems = oldArray.count – newArray.count    […]

Resize NSImage Proportionally (Swift)

I wanted a simple function to resize an image to a desired height, while keeping proportions. Here’s what I came up with (based on Marco implementation): extension NSImage {          func resizedImageTo(sourceImage: NSImage, newSize: NSSize) -> NSImage?{         if sourceImage.isValid == false {             […]

Get Date Day, Month or Year in Swift 3.0

Just a quick update to show how to get Date Day, Month or Year in Swift 3 //Here I’m creating the calendar instance that we will operate with: let calendar = NSCalendar.init(calendarIdentifier: NSCalendar.Identifier.gregorian)         //Now asking the calendar what month are we in today’s date: let currentMonthInt = (calendar?.component(NSCalendar.Unit.month, from: Date()))!           //Now […]

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 = […]

Switching NSViewControllers from NSWindowController

This has taken quite some time to crack as there was not that much available information online.  I wanted a very simple way to change the NSViewController of a window on the fly by using code.  The solution I ended up with is quite easy, on the NSWindowController I load the default NSViewController by typing […]