How to identify calling method from a called method in swift

后端 未结 2 1408
刺人心
刺人心 2021-01-23 08:20

here is a scenario

func callingMethod_A {
  self.someCalculation()
}

func callingMethod_B{
  self.someCalculation()
}

func someCalculation{
//how to find who          


        
2条回答
  •  攒了一身酷
    2021-01-23 08:55

    You can use Thread.callStackSymbols like this

    func callingMethod_A() {
        self.someCalculation()
    }
    
    func callingMethod_B(){
        self.someCalculation()
    }
    
    func someCalculation(){
        let origin = Thread.callStackSymbols
        print(origin[0])
        print(origin[1])
    }
    

提交回复
热议问题