指针取消引用 Swift
Pointer dereferencing Swift
在C
& Objective C
中,我们曾经解引用一个指针并获取值如下:
p->a = 1
or int x = p->a
但我在 Swift 中找不到等效项。我有一个 return 类型 UnsafePointer
到 AudioStreamBasicDescription?
我需要读取其成员值。
您使用 UnsafePointer 上的 pointee
属性 访问它指向的内存。因此,您的 C 示例将读作 let x = p.pointee.a
.
在C
& Objective C
中,我们曾经解引用一个指针并获取值如下:
p->a = 1
or int x = p->a
但我在 Swift 中找不到等效项。我有一个 return 类型 UnsafePointer
到 AudioStreamBasicDescription?
我需要读取其成员值。
您使用 UnsafePointer 上的 pointee
属性 访问它指向的内存。因此,您的 C 示例将读作 let x = p.pointee.a
.