将UnsafeMutableRawPointer转换为swift3

时间:2016-10-28 05:17:32

标签: swift2 swift3

我在swift2中有这段代码

  private var RecordedDurationContext = UnsafeMutablePointer<Void>.alloc(1)

如何转换为swift3

1 个答案:

答案 0 :(得分:0)

private var RecordedDurationContext = UnsafeMutableRawPointer.alloc(1)

let a = UnsafeMutablePointer<Int>.allocate(capacity: 1)
a.pointee = 42

print("a's value: \(a.pointee)") // 42 

a.deallocate(capacity: 1)