Hide NSUserNotification after certain time

It's actually very simple to do this, using NSObject's performSelector:withObject:afterDelay: method.

Because you're scheduling the notification delivery after a certain time interval, you need to add the additional delay before dismissing, to the initial delay before delivering. Here, I've written them out as constants of 10 seconds before delivery, and 2 seconds before dismissal:

let delayBeforeDelivering: NSTimeInterval = 10
let delayBeforeDismissing: NSTimeInterval = 2

let notification = NSUserNotification()
notification.title = "Title"
notification.deliveryDate = NSDate(timeIntervalSinceNow: delayBeforeDelivering)

let notificationcenter = NSUserNotificationCenter.defaultUserNotificationCenter()

notificationcenter.scheduleNotification(notification)

notificationcenter.performSelector("removeDeliveredNotification:",
    withObject: notification,
    afterDelay: (delayBeforeDelivering + delayBeforeDismissing))

And for Swift 5 you can use the following:

let delayBeforeDelivering: TimeInterval = 10
let delayBeforeDismissing: TimeInterval = 2

let notification = NSUserNotification()
notification.title = "Title"
notification.deliveryDate = Date(timeIntervalSinceNow: delayBeforeDelivering)

let notificationcenter = NSUserNotificationCenter.default

notificationcenter.scheduleNotification(notification)

notificationcenter.perform(#selector(NSUserNotificationCenter.removeDeliveredNotification(_:)),
                with: notification,
                afterDelay: (delayBeforeDelivering + delayBeforeDismissing))