[swift-users] Reflection in Swift 3?

Rick Mann rmann at latencyzero.com
Sun Nov 13 01:55:54 CST 2016


> On Nov 12, 2016, at 22:47 , David Sweeris <davesweeris at mac.com> wrote:
> 
> 
>> On Nov 13, 2016, at 00:38, Rick Mann via swift-users <swift-users at swift.org> wrote:
>> 
>> So, it seems there's still no way to do something like instantiate a class given only its name (as a String)?
>> 
>> In my situation, I have a number of subclasses (or protocol implementations), which parallel some other class hierarchy. I need to dynamically create one based on the name of another. I don't want the latter classes to "know" anything about the former.
> 
> Not that I know of... If this is all your code, can you fake it by switching over the type's name?

Yeah, it just happens in a few places, would be nice to write the code once and then just ensure classes exist. I know I could do it subclassing NSObject, but Swift really ought to have proper reflection.


-- 
Rick Mann
rmann at latencyzero.com




More information about the swift-users mailing list