-
-
Save kingiol/773e2107a1aaea3c14bd21920c6a85a8 to your computer and use it in GitHub Desktop.
Get memory address in Swift
This file contains hidden or 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 hidden or 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