I got a vector like this:
vector<Vec3f> myCoolVector
that gets filled with arrays like [1.0, 2.0, 3.1]
and [4.2, 2.1, 7.7]
, ...
.
I'd like to convert the myCoolVector
back to a 2d-array of floats
to send it back to Swift as a simple multidimensional Float Array (like this: [[Float]]
).
But what I get returned (to Swift) is a variable with this crazy type:
Optional<UnsafeMutablePointer<Optional<UnsafeMutablePointer<Float>>>>
...instead of just this type:
[[Float]]
.
Please have a look at my code:
(1) Code - C++:
+(float **)myCoolFunction {
vector<Vec3f> myCoolVector
// here fillMyCoolVector() fills the myCoolVector - NICE
float **floatArrayBackToSwift;
floatArrayBackToSwift = new float*[myCoolVector.size()];
for( size_t i = 0; i < myCoolVector.size(); i++ )
{
ary[i] = new float[3];
ary[i][0] = myCoolVector[i][0];
ary[i][1] = myCoolVector[i][1];
ary[i][2] = myCoolVector[i][2];
}
return floatArrayBackToSwift;
}
(2) Code - Swift:
let floatArray = MyBridge.myCoolFunction() // should be [[1.0, 2.0, 3.1], [4.2, 2.1, 7.7], ...]
print(floatArray)
My question: How can I send the myCoolVector
as a simple 2d-Array like [[Float]]
back to Swift?
Any help would be very appreciated!