robnik
1
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.
3 Likes
robnik
3
Thanks, that library is interesting. I wonder if it depends on non-public binary layouts in a way that could cause apps using the library to break over time.
If my understanding is correct - only if there are breaking changes in Swift ABI. But then your app would need to recompiled.