IOKit on iOS/iPadOS 16.0+

According to https://developer.apple.com/documentation/iokit IOKit is supported for iOS/iPadOS 16.0+.

I was trying to figure out what that exactly meant by using Xcode 14.1 and build for iPadOS 16.1. But I just get "No such module 'IOKit'" if I have

import IOKit

in any Swift file.

Wondering if it is an error in the documentation or if I have to do something extraordinary?

Thanks :)

Answered by DTS Engineer in 735727022

The IOKit framework is not modularised, so you can’t import it directly from Swift. You can import it from a C-base language:

#include <IOKit/IOKitLib.h>

You have a couple of options on the Swift side:

  • Create Objective-C classes that implement the functionality you need on top I/O Kit, and then call those from Swift.

  • Import I/O Kit in a bridging header and call it directly from Swift.

I’ve done both and, honestly, I’m not sure which one I prefer (-:

Note The above is is no different from the story on macOS.

Keep in mind that I/O Kit on iPadOS is there so folks can talk to DriverKit drivers; it’s not the general-purpose ‘do everything’ API that you have on macOS.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

The IOKit framework is not modularised, so you can’t import it directly from Swift. You can import it from a C-base language:

#include <IOKit/IOKitLib.h>

You have a couple of options on the Swift side:

  • Create Objective-C classes that implement the functionality you need on top I/O Kit, and then call those from Swift.

  • Import I/O Kit in a bridging header and call it directly from Swift.

I’ve done both and, honestly, I’m not sure which one I prefer (-:

Note The above is is no different from the story on macOS.

Keep in mind that I/O Kit on iPadOS is there so folks can talk to DriverKit drivers; it’s not the general-purpose ‘do everything’ API that you have on macOS.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

IOKit on iOS/iPadOS 16.0+
 
 
Q