import IOKit.pwr_mgt /// Keeps the display (and therefore the system) awake while held. public final class SleepBlocker { private var assertion: IOPMAssertionID = 0 public init?(reason: String) { let result = IOPMAssertionCreateWithName( kIOPMAssertionTypePreventUserIdleDisplaySleep as CFString, IOPMAssertionLevel(kIOPMAssertionLevelOn), reason as CFString, &assertion ) guard result == kIOReturnSuccess else { return nil } } deinit { IOPMAssertionRelease(assertion) } }