2016-10-03 83 views
1

下面的代碼在早期版本的Swift中工作,現在編譯器拒絕它。 我需要這個函數來從ObjectiveC與Swift交互。在Swift 3中寫入UnsafeMutablePointer

@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; 
    } 

回答

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; 
} 

添加INOUT鄂木斯克參數應該工作了。

1

錯誤消息是誤導性的。的 Unsafe(Mutable)Pointermemory財產已被重命名爲pointee斯威夫特3:

let z = someFunction() 
omsk.pointee = z 
相關問題