Hacker News new | ask | show | jobs
by pstop 4368 days ago
Yea, I noticed this in the undocumented API's, but haven't played much with it. It's definitely cleaner than C#'s reflection implementation, but more limited as well. Though for most uses, knowing the limitations solves most of the issues the OP has.
2 comments

This presentation covers some of the reflection API in Swift: http://www.realm.io/news/swift-unchartered-territory-swift-i...

While it is clearly still somewhat limited, it does seem like there is potential for it to evolve into a really robust reflection API.

I disagree. Right now it doesn't seem like a lot of things aren't possible in swift unless there is a LOT of undocumented API.

Dynamic method compilation that you would need to make an equivalent of DynamicProxy just doesn't seem possible. What's funny is that the #1 thing I would state is not possible in Swift is Core Data.

I am not sure how clean the reflect() function is in swift right now as it stands.

reflect(User()) requires me to new up an instance of the object to reflect. This is a static(ish) language right? Why do I need to reflect a specific instance?

In c# you just go typeof(User).GetProperties|GetMethods|GetFields etc. You don't need to new up an object, all the required information is stored as metadata for the type after compilation.

I understand in a universe where you can dynamically add methods/fields/properties etc. to a type you'd want the specific instance at runtime to reflect, but as far as I know Swift does away with this dynamism on purpose.