指针取消引用 Swift

Pointer dereferencing Swift

C & Objective C中,我们曾经解引用一个指针并获取值如下:

  p->a = 1
  or int x = p->a

但我在 Swift 中找不到等效项。我有一个 return 类型 UnsafePointerAudioStreamBasicDescription? 我需要读取其成员值。

您使用 UnsafePointer 上的 pointee 属性 访问它指向的内存。因此,您的 C 示例将读作 let x = p.pointee.a.