Last active
September 12, 2023 08:25
-
-
Save onevcat/bbad1fcc1e9575ab1c0a8c1e1e659e30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
var a = 123 | |
var cpa = a | |
class Miao {} | |
var c = Miao() | |
var cc = c | |
struct S {} | |
var s = S() | |
var cps = s | |
var likes = ["comdy", "animation", "movies"] | |
var cpLikes = likes | |
var str = "str" | |
var cpStr = str | |
func address<T: AnyObject>(of object: T) -> String { | |
let addr = unsafeBitCast(object, to: Int.self) | |
return String(format: "%p", addr) | |
} | |
func address(of object: UnsafeRawPointer) -> String { | |
let addr = Int(bitPattern: object) | |
return String(format: "%p", addr) | |
} | |
print("Class") | |
print(address(of: c)) | |
print(address(of: cc)) | |
print("Int") | |
print(address(of: &a)) | |
print(address(of: &cpa)) | |
print("Struct") | |
print(address(of: &s)) | |
print(address(of: &cps)) | |
print("Array") | |
print(address(of: &likes)) | |
print(address(of: &cpLikes)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment