Skip to content

Instantly share code, notes, and snippets.

@michaelmcguire
Created June 29, 2015 19:23
Show Gist options
  • Save michaelmcguire/25ae4d84d9bb139495cf to your computer and use it in GitHub Desktop.
Save michaelmcguire/25ae4d84d9bb139495cf to your computer and use it in GitHub Desktop.
Getting device list in Swift using libimobiledevice
import Foundation
var i: CInt = 0
var device_list: UnsafeMutablePointer<UnsafeMutablePointer<Int8>> = nil
idevice_get_device_list(&device_list, &i)
print("number of devices: \(i)")
let array = Array(UnsafeBufferPointer(start: device_list, count: Int(i)))
for var device in array {
if let deviceName = String.fromCString(device) {
print("\tdevice: \(deviceName)")
}
}
idevice_device_list_free(device_list)
@kiontupper
Copy link

I know this is old, but how did you get libimobiledevice to link with Swift properly? I have everything installed (ideviceinfo works), but adding libimobiledevice.dylib as a dependency in Xcode doesn't make it available in Swift. I wouldn't normally bother you but I couldn't find anything online.

@robm92
Copy link

robm92 commented May 20, 2022

I know this is old, but how did you get libimobiledevice to link with Swift properly? I have everything installed (ideviceinfo works), but adding libimobiledevice.dylib as a dependency in Xcode doesn't make it available in Swift. I wouldn't normally bother you but I couldn't find anything online.

Try adding the source to the Xcode project then importing the libimobiledevice.h file into the bridging header

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment