Last active
November 7, 2025 17:46
-
-
Save usagimaru/76852d6102413c05b549f91a522e60cd to your computer and use it in GitHub Desktop.
Copy instance variables, methods or properties from specific class with Objective-C runtime API via 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
| #import ObjectiveC | |
| var count: UInt32 = 0 | |
| if let ivars = class_copyIvarList(NSObject.self, &count) { | |
| for i in 0..<Int(count) { | |
| let ivar = ivars[i] | |
| if let name = ivar_getName(ivar) { | |
| print("ivar: ", String(describing: String(utf8String: name))) | |
| } | |
| } | |
| } |
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
| #import ObjectiveC | |
| var count: UInt32 = 0 | |
| if let methods = class_copyMethodList(NSObject.self, &count) { | |
| for i in 0..<Int(count) { | |
| let method = methods[i] | |
| let sel = method_getName(method) | |
| let name = sel_getName(sel) | |
| print("method: ", String(describing: String(utf8String: name))) | |
| } | |
| } |
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
| #import ObjectiveC | |
| var count: UInt32 = 0 | |
| if let props = class_copyPropertyList(NSObject.self, & count) { | |
| for i in 0..<Int(count) { | |
| let prop = props[i] | |
| let name = property_getName(prop) | |
| print("property: ", String(describing: String(utf8String: name))) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment