Helium3 Helium3 - 1 year ago 60
Swift Question

Read a double * in Swift

I have an Obj-C method that returns a

double *
, how is this accessed in Swift as a

I get this error

Cannot convert value of type 'UnsafeMutablePointer<Double>' to expected argument type 'Double'

I am calling this
- (double * _Nonnull) modIntensityForDestination:(int) destination;

and failing when I do this

let intensity = audioEngine.modIntensityForDestination(Int32(modDestinationID))

I have tried
but cant seem to get it working.

Answer Source

If the method returns a pointer to a single floating point number then you can dereference it with .memory:

let intensity = audioEngine.modIntensityForDestination(...).memory

In Swift 3 it would be .pointee.