Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access iokit/pwr_mgt from swift?

I'm trying to write an OSX app (not iOS) that prevents the system from going to sleep when certain things are happening. To do so, I'm trying to access the pwr_mgt submodule of IOKit from a MacOS app using Swift.

In XCode, I've indicated that I want to use the IOKit framework, and in code, I'm have declared import IOKit. Although IOKit's classes/methods import fine (I can see them with auto-complete when I type IO*Whatever), the ones relating to power management don't show up.

I've tried to instead import IOKit.pwr_mgt, but the compiler complains that the submodule can't be found.

<unknown>:0: error: missing required module 'pwr_mgt'

From other documentation for how to do this with Objective-c, the classes that I need to access (amongst others) are:

  • IOPMAssertionCreateWithName
  • IOPMAssertionID
  • IOPMAssertionRelease
  • CFStringRef
  • CFSTR
like image 904
Marcosc Avatar asked Aug 02 '14 13:08

Marcosc


1 Answers

I'm not sure if there is a solution to this problem in older Xcode betas, but on Beta 7 (and I imagine in Xcode 6.1 too)

import IOKit.pwr_mgt

works fine in newer betas.

like image 86
radex Avatar answered Oct 14 '22 06:10

radex