How to represent Objc-C NSUInteger[] = {0,1,2} in Swift as UnsafeMutablePointer<UInt>?

JBlake

Objc-C header definition:

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

Sample objc-C code to use this function:

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

Swift expects:

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

How do I represent NSUInteger pageIndexes[] = {0}; in Swift as a UnsafeMutablePointer<UInt>?

Martin R

You can simply pass a Swift [UInt] array as in-out argument with &, this passes the address of the array element storage to the (Objective-)C function:

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

For more information, see

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to convert String to UnsafeMutablePointer<UInt8> ? Swift 3

How to create UnsafeMutablePointer<UnsafeMutablePointer> in swift

Memset to UnsafeMutablePointer<UInt8> in swift

Convert unsinged char array from objective-c to UnsafeMutablePointer<UInt8> swift

How to convert Objc c Enum to NSValue in swift

How to use UnsafeMutablePointer in Swift 3?

How to use UnsafeMutablePointer<OpaquePointer> in Swift?

Swift convert [UIn16] to UnsafeMutablePointer<UInt16>

Swift 2 - UnsafeMutablePointer<Void> to object

Using UnsafeMutablePointer and CFRunLoopObserverContext in swift 2

How to use nesting defines from objc/c in swift?

How to create UnsafeMutablePointer<CGPoint> Object in swift

How to cast self to UnsafeMutablePointer<Void> type in swift

How to dealloc UnsafeMutablePointer referenced from Swift struct

how to loop through elements of array of <UnsafeMutablePointer> in Swift

How to use UnsafeMutablePointer<T?> in swift 3

When porting Java code to ObjC, how best to represent checked exceptions?

Swift UnsafeMutablePointer & UnsafeMutablePointer<UnsafePointer<SomeType>>

How to represent magnitude for mass in Swift?

How to effectively represent htonl in swift?

Swift: fill data into unsafeMutablePointer of UInt8 type doesn't work

Objc-C to Swift: How to create a property in Swift that guarantees it's of a certain type when callers use it?

UnsafeMutablePointer in swift as replacement for properly sized C Array in Obj-C

How to pass NSUInteger into NSDictionary

How do I represent uint8 literals in Java

How to get length of a UnsafeMutablePointer<Object> written to a OpenSSL BIO in Swift?

How to cast UnsafeMutableRawPointer! to UnsafeMutablePointer<Float> in Swift 3.0 or newer?

How to do pointer arithmetic on UnsafeMutablePointer and get String in Swift 3

How to pass swift enum with @objc tag