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 :)

Accepted Reply

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"

  • Everything is so obvious after you explained them! Thanks Quinn ❤️

    PS. Can you see from the documentation it is not modularised? PS. What is the criterion for when a framework gets modularised?

    Thanks again! 🤠

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

    For what it's worth, I don't think this is true. import IOKit works fine in Swift in a macOS only target. It's only when building for iOS that I can't import the framework directly and have to put it in a bridging header instead.

Add a Comment

Replies

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"

  • Everything is so obvious after you explained them! Thanks Quinn ❤️

    PS. Can you see from the documentation it is not modularised? PS. What is the criterion for when a framework gets modularised?

    Thanks again! 🤠

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

    For what it's worth, I don't think this is true. import IOKit works fine in Swift in a macOS only target. It's only when building for iOS that I can't import the framework directly and have to put it in a bridging header instead.

Add a Comment