Last active
October 10, 2024 04:39
-
-
Save matsuda/0dbb9721a9ee8cddb8b09d885c8f4290 to your computer and use it in GitHub Desktop.
Get memory address in Swift
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
/// | |
/// https://stackoverflow.com/a/29741007 | |
/// | |
let s = Struct() // Struct | |
withUnsafePointer(to: s) { | |
print(String(format: "%p", $0) | |
} | |
/// | |
/// http://stackoverflow.com/a/36539213/226791 | |
/// | |
func addressOf(_ o: UnsafeRawPointer) -> String { | |
let addr = unsafeBitCast(o, to: Int.self) | |
return String(format: "%p", addr) | |
} | |
func addressOf<T: AnyObject>(_ o: T) -> String { | |
let addr = unsafeBitCast(o, to: Int.self) | |
return String(format: "%p", addr) | |
} |
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
/// | |
/// 強制的にメモリーワーニングを発生させる(実機) | |
/// | |
let selector = Selector("_performMemoryWarning") | |
if UIApplication.shared.responds(to: selector) { | |
UIApplication.shared.perform(selector) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment