[swift-evolution] Dynamic Class/Struct Definition At Run Time

Anton Zhilin antonyzhilin at gmail.com
Tue Oct 11 12:40:20 CDT 2016

Hello Ted,
First of all, this topic belongs to reflection, which is specifically
stated to be out of scope of Swift 4 Phase 1. So all considerations are
purely theoretical for now.
That said, I also thought about this problem. The best I could imagine is
something along the following lines:

var builder = StructBuilder(name: "Person")
builder.addProperty(name: "name", type: String.self)
builder.addProperty(name: "age", type: Int.self)
builder.addComputedProperty(name: "description", getter: { (this: Any)
-> String in ... })
builder.addComformance(CustomStringConvertible.self)let type: Any.Type
= builder.build()

Obviously, to interact with such dynamic types and their objects, we need
the whole working reflection system that we don’t have right now.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161011/76225d4d/attachment.html>

More information about the swift-evolution mailing list