gpt4 book ai didi

objective-c - 如何在 Swift 中将 Objc-C NSUInteger[] = {0,1,2} 表示为 UnsafeMutablePointer

转载 作者:搜寻专家 更新时间:2023-10-31 22:36:42 24 4
gpt4 key购买 nike

Objc-C header 定义:

- (int)printPDFAtPath:(NSString *)pdfPath pages:(NSUInteger [])indexes length:(NSUInteger)length copy:(int)nCopy;

使用此函数的示例 objc-C 代码:

NSUInteger pageIndexes[] = {0};
printResult = [self.ptp printPDFAtPath:selectedPDFFilePath pages:pageIndexes length:length copy:self.numberOfPaper];

swift 期望:

func printPDF(atPath pdfPath: String!, pages indexes: UnsafeMutablePointer<UInt>!, length: UInt, copy nCopy: Int32) -> Int32

我如何表示 NSUInteger pageIndexes[] = {0};在 Swift 中作为 UnsafeMutablePointer<UInt>

最佳答案

您可以简单地将 Swift [UInt] 数组作为输入输出参数传递给 &,这会将数组元素存储的地址传递给 (Objective-) C函数:

var pageIndexes: [UInt] = [1, 2, 3]
ptp.printPDF(atPath: "path", pages: &pageIndexes, length: UInt(pageIndexes.count), copy: 1)

有关详细信息,请参阅

关于objective-c - 如何在 Swift 中将 Objc-C NSUInteger[] = {0,1,2} 表示为 UnsafeMutablePointer<UInt>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57730476/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com