ios - swift 打印地址的问题
怪我咯
怪我咯 2017-04-18 09:51:11
0
1
422
func test(_ arr: [String]) {
    
    for var i in arr {
        withUnsafePointer(to: &i) {
            print(" str value \(i) has address: \($0)")
        }
    }
}

var a = ["1","2","3"]

test(a)

打印结果:
str value 1 has address: 0x00007fff5dff9fc0
str value 2 has address: 0x00007fff5dff9fc0
str value 3 has address: 0x00007fff5dff9fc0

如果我想打印整个数组的地址怎么打?

如果数组里不是字符串,是其他类型,改怎么打?找了很久没找到,特此来提问

怪我咯
怪我咯

走同样的路,发现不同的人生

membalas semua(1)
伊谢尔伦
// 数组,无论什么数组都可以
let str = ["hello", "world", "!\r\n"]

// 查看一下数组
print(str)

//打印数组的地址,而不是单个元素的地址
str.withUnsafeBytes { print(
public class Ball {
  var color = 0
  var tag = "foot"
  public init(color: Int = 0, tag: String = "beach") {
    self.color = color
    self.tag = tag
  }
}

var ball = Ball()
/// 获取对象指针并打印地址
withUnsafePointer(to: &ball) { pointer in
  print(pointer)
}
) }
rrreee
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan