Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of uint8_t in swift?

There's a method in an obj-c/c++ framework that takes a uint8_t and a regular int:

- (bool)push:(uint8_t *)buf length:(int)len;

I used a bridger file to have access to this method, but when I call it in swift using UInt8 and Int I get the following error:

Cannot invoke 'push' with an argument list of type '(UInt8, length: Int)'

How can I make it work?

like image 871
SemAllush Avatar asked Dec 01 '25 00:12

SemAllush


1 Answers

The method expects a pointer to an array of elements of UInt8 type and an Int32 value. You can do something like this:

var buffer: [UInt8] = [0, 1, 2]
yourObject.push(UnsafeMutablePointer<UInt8>(buffer), length: Int32(buffer.count))

Check out here how pointers should be handled: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html

like image 57
Srđan Avatar answered Dec 03 '25 15:12

Srđan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!