Zeist Zeist - 9 months ago 81
Swift Question

Check Mac battery percentage in swift

I have been trying to check the mac battery level programmatically.it can be done on ios but i want to do it in mac.i found some resources on stackoverflow but those links were deprecated. Any Ideas?


First create a "Umbrella-Bridging-Header.h" with the content:

#import <IOKit/ps/IOPowerSources.h>

then in main.swift

import Foundation

println("Hello, World!")
let timeRemaining = IOPSGetTimeRemainingEstimate ()
println("timeRemaining: \(timeRemaining)")