I’d like to use reflection to eliminate boilerplate in some SQLite code that I'm writing (for about the 10th time). I see Mirror
, but it doesn't look like it does what I want.
Given a type, like this:
struct Foo {
var id: UUID
var name: String
var startDate: Date?
var amount: Double?
func bar() { ... }
}
Is it it possible to:
- Iterate over those properties without an instance? (
Mirror
shows me property names if I have an instance.) - See the declared types of the properties? (
Mirror
just gives me the names and run-time values, it seems.) - See the functions like
bar
declared in the type?
1 and 2 would help me write something like createTable(for: Foo.self)
, because I could loop over the properties and decide what SQLite column styles to use.