Swift: Fetching methods for a Cocoa class

Just because.

func ClassMethods(c : AnyClass) -> [String] {
    var num : UInt32 = 0
    var results = [String]()
    let methods = class_copyMethodList(c, &num) // Thanks Jordan Rose
    for index in 0..<numericCast(num) {
        let method : Method = methods[index]
        let selector : Selector = method_getName(method)
        results += [String(_sel:selector)]
    }
    return results
}
import XCPlayground
println(ClassMethods(NSClassFromString("DVTPlaygroundCommunicationSender")))

One Comment

  • sweet šŸ™‚ thanks erica!