0

I used to find a debug technique in an article, but I forget how to do it now. I describe it below and hope someone knows.

I remember that we can write some code anywhere such as in a ViewController's viewDidLoad.

override func viewDidLoad() {
    super.viewDidLoad()

/*Some magic code here

Set a breakpoint here among these code

Some magic code here
*/   

}

Then run the project in simulator. And when pressing the pause button in Xcode's debug area.It will jump to the breakpoint we set among the magic code directly.

enter image description here

Does anyone know how to do that?

PS: The magic code can be put in anywhere. And we can jump to the breakpoint in it when pressing pause button.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
LinShiwei
  • 1,042
  • 14
  • 17
  • 1
    Breakpoints allows you to pause the execution of your program up to a certain moment. [I think this can help much more](https://medium.com/yay-its-erica/xcode-debugging-with-breakpoints-for-beginners-5b0d0a39d711) – Balasubramanian Jul 20 '17 at 13:27

1 Answers1

0

Clicking the pause button pauses the execution of your application. In order to hit your breakpoint, you need to run the code attached to it. Once this code has been executed, and the breakpoint is hit, you can click the play button to continue your application's execution, which will hit any other breakpoints in your code (assuming the code attached the said future breakpoint(s) is run).

ZGski
  • 2,398
  • 1
  • 21
  • 34
  • I know how breakpoint works. I was surprise when I first read that article and knew the technique that we can use to jump to anywhere when press pause button. And I tried that technique myself and it worked just like what I describe above. Unfortunately I forget how to do it now. Maybe we can use NSRunloop to do it ? – LinShiwei Jul 20 '17 at 13:42
  • 1
    You can't just jump to a breakpoint unless the code it's attached to is being run. – ZGski Jul 20 '17 at 17:11