我该如何将'[Int]'也投给'UnsafeMutablePointer <Int32>?”?

时间:2019-12-05 23:22:17

标签: objective-c swift

我正在制作的应用程序中有一个名为time_diff的变量。我需要将其传递给采用UnsafeMutablePointer?的obj-c函数。

迅速:

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

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

1 个答案:

答案 0 :(得分:0)

请参阅Apple文档中的“手动内存管理”:https://developer.apple.com/documentation/swift/swift_standard_library/manual_memory_management

在这种情况下,如果函数以UnsafeMutablePointer<Int32>类型的time_diff形式导入到Swift中,则应将swift中的数组声明为[Int32]而不是{{1} }。然后将其作为[Int](一个&time_diff参数)传递。