[swift-users] Instantiate Swift class from string
Harlan Haskins
harlan at harlanhaskins.com
Thu Dec 10 09:26:33 CST 2015
IIRC this isn’t possible because there’s no Runtime to query for classnames (it’s inherently unsafe anyway).
You might want to look into a better way of doing that you’re trying to do.
— Harlan
> On Dec 10, 2015, at 12:42 AM, Matthew Davies via swift-users <swift-users at swift.org> wrote:
>
> I am using the Swift build tool & package manager. I'm trying to figure out how to instantiate a class from a string. For instance, in PHP I can do:
>
> $instance = new $className
>
> I can (in the iOS & OS X runtimes) use "NSClassFromString", but this is unavailable in the Swift build tool. How can I (or can I?) get the same functionality?
>
>
>
> Matthew Davies
> Junior Developer, GeoStrategies <http://geostrategies.com/>
> Director of Photography, OffBlock Films <http://offblockfilms.com/>
> 209-225-3246 <tel:209-225.3246> | 209-202-3284 <tel:209-202-3284> | matthew at daviesgeek.com <mailto:matthew at daviesgeek.com> | daviesgeek.com <https://daviesgeek.com/>
> <http://facebook.com/daviesgeek> <http://us.linkedin.com/in/daviesgeek> <http://twitter.com/daviesgeek> <http://daviesgeek.com/feed.xml> <http://github.com/daviesgeek>
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20151210/ca25a100/attachment.html>
More information about the swift-users
mailing list