1

Is it possible to determine the class of Any object at runtime? And convert the class into human readable string?

Also is it possible to obtain list of methods that this object supports?

class Foo {
    let desc = "Foo"
}

class Bar {
    let desc = "Bar"
}

var x:Any = Foo()

var className = "___WHAT COMES HERE_____"
println("x is class=\(className)")
// also print list of methods on x if possible

x = Bar()
className = "___WHAT COMES HERE_____"
println("x is class=\(className)")
Maria Zverina
  • 10,863
  • 3
  • 44
  • 61
  • 1
    The main header contains Mirror and Reflectable protocols that seem tantalizingly relevant. However I wasn't able to make them work. – Maria Zverina Jun 09 '14 at 02:29
  • 1
    @CezaryWojcik until the search indexing catches up, duplicates are going to happen. My understanding is that the index server got switched on the first of June, and the swift-language tag came aboard on the second. I know that searching for `[swift-language] ` is still not showing hits for topics I _know_ have been posted here. – pjs Jun 09 '14 at 05:05

1 Answers1

0

Nope, and Mirror and Reflectable are just there for the IDE.

rougeExciter
  • 7,435
  • 2
  • 21
  • 17