Tag: 不安全指针

如何将数组转换为UnsafeMutablePointer <UnsafeRawPointer?> Swift 3.0?

这是我以前版本的Swift中可用的代码: let imageOptionsDictKeys = [ kCVPixelBufferPixelFormatTypeKey, kCVPixelBufferWidthKey, kCVPixelBufferHeightKey, kCVPixelBufferOpenGLESCompatibilityKey, kCVPixelBufferIOSurfacePropertiesKey] let imageOptionsDictValues = [ cvPixelFormatType, frameW, frameH, boolYES] var keyCallbacks = kCFTypeDictionaryKeyCallBacks var valueCallbacks = kCFTypeDictionaryValueCallBacks let imageOptions = CFDictionaryCreate(kCFAllocatorDefault, UnsafeMutablePointer(imageOptionsDictKeys), UnsafeMutablePointer(imageOptionsDictValues), 4, &keyCallbacks, &valueCallbacks) 在Swift 3.0中进行更改后,我必须将我的键和值数组转换为UnsafeMutablePointer<UnsafeRawPointer?>来创buildCFDictionary。 这条路: let imageOptionsDictKeysPointer = UnsafeMutablePointer<UnsafeRawPointer?>.allocate(capacity: 1) imageOptionsDictKeysPointer.initialize(to: imageOptionsDictKeys) 给出一个错误访问错误。 阅读文档后,我试图编译这个代码: let imageOptionsDictKeys = [kCVPixelBufferPixelFormatTypeKey, kCVPixelBufferWidthKey, kCVPixelBufferHeightKey, kCVPixelBufferOpenGLESCompatibilityKey] let […]

在Swift 2.0中创build一个CMSampleBuffer的副本

这已经被问过了,但是自从被问到以后,Swift肯定会发生一些变化。 我试图存储从AVCaptureSession返回的CMSampleBuffer对象稍后处理。 经过一番实验,我发现AVCaptureSession必须重用其CMSampleBuffer引用。 当我试图保持超过15个会话挂起。 所以我想我会制作样本缓冲区的副本。 但我似乎无法得到它的工作。 这是我写的: var allocator: Unmanaged<CFAllocator>! = CFAllocatorGetDefault() var bufferCopy: UnsafeMutablePointer<CMSampleBuffer?> let err = CMSampleBufferCreateCopy(allocator.takeRetainedValue(), sampleBuffer, bufferCopy) if err == noErr { bufferArray.append(bufferCopy.memory!) } else { NSLog("Failed to copy buffer. Error: \(err)") } 这将不会被编译,因为它说Variable 'bufferCopy' used before being initialized了Variable 'bufferCopy' used before being initialized 。 我看了很多例子,他们会编译或不工作,否则他们不会编译。 有人看到我在这里做错了吗?

Swift UnsafeMutablePointer <Unmanaged <CFString>?>分配和打印

我是新来的迅速,我有一些困难来处理非托pipeCFString(或NSString)的指针。 我正在研究一个CoreMIDI项目,暗示了UnsafeMutablePointer?>的使用,正如你在这个函数中看到的那样: func MIDIObjectGetStringProperty(_ obj: MIDIObjectRef, _ propertyID: CFString!, _ str: UnsafeMutablePointer<Unmanaged<CFString>?>) -> OSStatus 我的问题是我想分配一个缓冲区来接收属性(_str)的内容,然后调用上面的函数,最后使用println在控制台中打印内容。 目前我写这个: // Get the first midi source (I know it exists) var midiEndPoint : Unmanaged<MIDIEndpointRef> = MIDIGetSource(0) //C reate a "constant" of 256 let buf = NSMutableData(capacity: 256) // Allocate a string buffer of 256 characters (I'm not even sure […]