Print the variable memory address in SWIFT

Is there anyway to simulate the [NSString stringWithFormat:@”%p”,myVar] code with the new swift language?

For example:

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

Swift 2

Now this is the standard Part of the library: 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

For Swift 3, use withUnsafePointer:

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

Anyway, use the new swift language to simulate the [NSString stringWithFormat:@"%p",myVar] code?

For example:

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

Swift 2

Now this is part of the standard library: 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

For Swift 3, use withUnsafePointer:

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

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4154 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.