When using Swift, is there a way of using Xcode or any other tool to find out which initializer was used to instantiate a class? Let me provide this example from SwiftUI:
List {
ForEach(names.array, id: .self) {
name in Text(name)
}
}
To understand the mechanics of List
and build more elaborate lists, I’d want to know how this list was instantiated. The documentation shows me that List
has around ten initializers, and given that I’m not an expert in the complex types involved, it’s hard for me to find out which one was used.
2
Answers
Fundamentally, no.
There may be signatures left on the final object based on which initialisers were used, but they would all be implementation specific, and potentially local to whatever version of the compiler you were using in the moment.
The
List(…)
initialiser makes exactly one promise, and that is that you get aList
back.Trying to extract more information than that is a fool’s errand; the information is simply not (by necessity) there.
If you don’t mind adding explicit
init
, Cmd-clicking oninit
will move you to the right header.