How do I recover the stack trace in Swift, so that I can find out which method was the last one called before a crash?
What I want to replicate in Swift is this method in C#:
public static Assembly GetComponentInInvocationDegree(int invocationDegree)
{
if (invocationDegree < 0) throw new ArgumentOutOfRangeException("Cannot set out of range value: invocation degree must be greater than or equal to zero");
var stackInvocacion = new StackTrace().GetFrames();
if (invocationDegree > 0)
{
int invokingAssemblyIndex = 0;
string currentDegreeComponentName;
try
{
for (int currentDegree = 0; currentDegree < invocationDegree; currentDegree++)
{
currentDegreeComponentName = stackInvocacion[invokingAssemblyIndex].GetMethod().ReflectedType.Assembly.GetName().Name;
while (stackInvocacion[invokingAssemblyIndex].GetMethod().ReflectedType.Assembly.GetName().Name == currentDegreeComponentName) invokingAssemblyIndex++;
}
}
catch (Exception ex) { throw new InvalidOperationException(string.Format("Cannot get component in invocation degree: invocation degree {0} does not exist", invocationDegree), ex); }
return stackInvocacion[invokingAssemblyIndex].GetMethod().ReflectedType.Assembly;
}
return stackInvocacion[0].GetMethod().ReflectedType.Assembly;
}