有没有办法用新的Swift语言模拟Objective-C中的[NSString stringWithFormat:@"%p", myVar]
?
例如:
let str = "A String"
println(" str value \(str) has address: ?")
有没有办法用新的Swift语言模拟Objective-C中的[NSString stringWithFormat:@"%p", myVar]
?
例如:
let str = "A String"
println(" str value \(str) has address: ?")
这是标准库的一部分: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
对于Swift 3,使用withUnsafePointer
:
var str = "A String"
withUnsafePointer(to: &str) {
print(" str value \(str) has address: \($0)")
}