在swift中打印可变内存地址

前端之家收集整理的这篇文章主要介绍了在swift中打印可变内存地址前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
无论如何用新的 swift语言模拟[NSString stringWithFormat:@“%p”,myVar]代码

例如:

let str = "A String"
println(" str value \(str) has address: ?")

解决方法

斯威夫特2

现在这是标准库的一部分:unsafeAddressOf.

/// Return an UnsafePointer to the storage used for `object`.  There's
/// not much you can do with this other than use it to identify the
/// object

斯威夫特3

对于Swift 3,使用withUnsafePointer:

var str = "A String"
withUnsafePointer(to: &str) {
    print(" str value \(str) has address: \($0)")
}

猜你在找的Swift相关文章