I got this error in my code:
func getBatteryInfos(){ let snapshot = IOPSCopyPowerSourcesInfo().takeRetainedValue() // Pull out a list of power sources let sources = IOPSCopyPowerSourcesList(snapshot).takeRetainedValue() as Array // For each power source... for ps in sources { // Fetch the information for a given power source out of our snapshot let info = IOPSGetPowerSourceDescription(snapshot, ps).takeUnretainedValue() as Dictionary // Pull out the capacity if let capacity = info[kIOPSCurrentCapacityKey] as? Double, //Ambiguous reference to member 'subscript' let charging = info[kIOPSIsChargingKey] as? Int{ //Ambiguous reference to member 'subscript' batteryPercentage = capacity batteryState = charging print("Current battery percentage \(batteryPercentage)") print("Current state \(batteryState)") } }
I tried replacing info[kIOPSCurrentCapacityKey] with info["kIOPSCurrentCapacityKey"] , but the same error. I saw several questions about this error in StackOverflow, but all the answers do not work with my code.
I work with Xcode 8 Beta 6 and Swift3. In Swift 2, this code worked fine.
Any help is appreciated :-)
source share