简体   繁体   English

我怎样才能将 &#39;[Int]&#39; 也转换为 &#39;UnsafeMutablePointer<Int32> ?&#39;?

[英]How can I cast a '[Int]' too an 'UnsafeMutablePointer<Int32>?'?

I have a variable called time_diff in an app I'm making.我正在制作的应用程序中有一个名为 time_diff 的变量。 I need to pass it into an obj-c function that takes UnsafeMutablePointer?.我需要将它传递给一个接受 UnsafeMutablePointer? 的 obj-c 函数。

Swift:迅速:

var time_diff = [Int](repeating: 0, count: MAX_NODE)

Obj-C Function: Obj-C 功能:

- (instancetype) initWithRawDataX:(float *)x Y:(float*)y pressure:(float *)p time_diff:(int *)time penColor:(UInt32)penColor penThickness:(NSUInteger)thickness startTime:(UInt64)start_at size:(int)size normalizer:(float)inputScale

See Manual Memory Management in Apple's docs: https://developer.apple.com/documentation/swift/swift_standard_library/manual_memory_management .请参阅 Apple 文档中的手动内存管理: https : //developer.apple.com/documentation/swift/swift_standard_library/manual_memory_management

In this case, if the function is imported into Swift as having UnsafeMutablePointer<Int32> for the type of time_diff , you should declare the array in swift as [Int32] instead of [Int] .在这种情况下,如果功能被导入到快速作为具有UnsafeMutablePointer<Int32>为类型time_diff ,应该声明在迅速阵列作为[Int32]代替[Int] Then pass it as &time_diff (an inout argument).然后将其作为&time_diff (一个inout参数)传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM