0

How can I programatically inspect the type of a Swift object? Something similar to obtaining the class of an object in ObjectiveC with the class message.

So, if I have

func f(x: Int) -> Int{
    return x * 3
}

I want to get (Int)->Int as the type of f.

cfischer
  • 24,452
  • 37
  • 131
  • 214
  • Yes, in Xcode. Where else? O:-) – cfischer Sep 10 '14 at 12:58
  • I didn't get what you meant earlier. Will have a look later. :-) – Guido Hendriks Sep 10 '14 at 17:15
  • Why? You structure your code so that you expect closures of a certain type, and the compiler will complain if it doesn't match. This _should_ obviate the need for type checking. If you show why you need to do this, perhaps we can show you a better way. – Alex Wayne Sep 10 '14 at 18:45
  • @AlexWayne: In fact, I don't think that it's even *possible* to write code not to expect closures of a certain type known at compile-time. – newacct Sep 10 '14 at 21:30
  • @cfisher: But you know the type of `f`. It's written in your code. In what situation can you imagine that you don't know it? – newacct Sep 10 '14 at 21:33

0 Answers0