我有一个返回double *
的Obj-C方法,如何在Swift中将其作为Double
进行访问?
我收到此错误
Cannot convert value of type 'UnsafeMutablePointer<Double>' to expected argument type 'Double'
我称之为- (double * _Nonnull) modIntensityForDestination:(int) destination;
当我这样做时失败
let intensity = audioEngine.modIntensityForDestination(Int32(modDestinationID))
我试过withUnsafeMutablePointer
,但似乎无法让它发挥作用。
答案 0 :(得分:1)
如果方法返回指向单个浮点数的指针
然后你可以用.memory
取消引用它:
let intensity = audioEngine.modIntensityForDestination(...).memory
在Swift 3中,它将是.pointee
。