I found that this solution works in Swift as well.
Create a class or global variable
var activity: NSObjectProtocol?
And assign it after which App Nap will be disabled
activity = NSProcessInfo().beginActivityWithOptions(NSActivityOptions.UserInitiated, reason: "Good Reason")
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…