下面的代码在Swift的早期版本中工作,现在编译器拒绝它。 我需要这个函数来与ObjectiveC中的Swift互操作。
@objc public static func myFunc(jdUT: Double, _ lon: Double, _ lat: Double,
_ dayLen: Double, _ SbhDeg: Double, _ MgrbDeg: Double,
omsk: UnsafeMutablePointer<Double>)
{
var z = somefuncion()
// this line gives this error : Cannot assign to property: 'omsk' is a 'let' constant
omsk.memory=z;
}
答案 0 :(得分:3)
错误消息具有误导性。 memory
属性
在Swift 3中,Unsafe(Mutable)Pointer
已重命名为pointee
:
let z = someFunction()
omsk.pointee = z
答案 1 :(得分:1)
@objc public static func myFunc(jdUT: Double, _ lon: Double, _ lat: Double,
_ dayLen: Double, _ SbhDeg: Double, _ MgrbDeg: Double,
inout omsk: UnsafeMutablePointer<Double>)
{
var z = somefuncion()
// this line gives this error : Cannot assign to property: 'omsk' is a 'let' constant
omsk.memory=z;
}
在omsk参数之前添加inout。