加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在swift中打印可变内存地址

发布时间:2020-12-14 04:26:29 所属栏目:百科 来源:网络整理
导读:无论如何用新的 swift语言模拟[NSString stringWithFormat:@“%p”,myVar]代码? 例如: let str = "A String"println(" str value (str) has address: ?") 解决方法 斯威夫特2 现在这是标准库的一部分:unsafeAddressOf. /// Return an UnsafePointer to
无论如何用新的 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)")
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读