我需要一些帮助来转换这个
MIDIDeviceRef midiDevice = MIDIGetDevice(i);
NSDictionary *midiProperties;
MIDIObjectGetProperties(midiDevice, (CFPropertyListRef *)&midiProperties, YES);
NSLog(@"Midi properties: %d \n %@", i, midiProperties);
很快。我有这个,但我正忙着投出CFPropertList。
var midiDevice = MIDIGetDevice(index)
let midiProperties = NSDictionary()
MIDIObjectGetProperties(midiDevice, CFPropertyListRef(midiProperties), 1);
println("Midi properties: \(index) \n \(midiProperties)");
任何帮助都会很棒。
由于
答案 0 :(得分:7)
这是Swift中MIDIObjectGetProperties
的签名:
func MIDIObjectGetProperties(obj: MIDIObjectRef, outProperties: UnsafeMutablePointer<Unmanaged<CFPropertyList>?>, deep: Boolean) -> OSStatus
因此,您需要将UnsafeMutablePointer
传递给Unmanaged<CFPropertyList>?
:
var midiDevice = MIDIGetDevice(0)
var unmanagedProperties: Unmanaged<CFPropertyList>?
MIDIObjectGetProperties(midiDevice, &unmanagedProperties, 1)
现在您拥有自己的属性,但它们位于非托管变量中 - 您可以使用takeUnretainedValue()
方法将其删除,然后将生成的CFPropertyList
强制转换为{{ 1}}:
NSDictionary
结果:
if let midiProperties: CFPropertyList = unmanagedProperties?.takeUnretainedValue() {
let midiDictionary = midiProperties as NSDictionary
println("Midi properties: \(index) \n \(midiDictionary)");
} else {
println("Couldn't load properties for \(index)")
}