Skip to content

Instantly share code, notes, and snippets.

@velyan
Last active September 10, 2018 02:49
Show Gist options
  • Save velyan/c60d423ead3e5911098cea0ea9e3b1ee to your computer and use it in GitHub Desktop.
Save velyan/c60d423ead3e5911098cea0ea9e3b1ee to your computer and use it in GitHub Desktop.
NSObject Introspection
import Foundation
var count: UInt32 = 0
let list = class_copyMethodList(NSObject.self, &count)
var result: Set<String> = Set()
for i in 0 ..< count {
let x = list![Int(i)]
let nameString = NSStringFromSelector(method_getName(x))
if !(nameString.hasPrefix("_") || nameString.hasSuffix(":") || nameString.hasSuffix("_")) {
result.insert(nameString)
}
}
let list2 = class_copyPropertyList(NSObject.self, &count)
for i in 0 ..< count {
let x = list2![Int(i)]
let nameString = String(cString: property_getName(x))
result.insert(nameString)
}
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment