Summary of basic principles of iOS

This article mainly introduces three ways to explore the source code

  • 1, theSymbol breakpointThe form directly follows the process
  • 2, through thePress and hold the control+step into
  • 3. Compile the view and process

Now, how do these three methods find the source library of the function, using alloc as an example

1.Symbol breakpointDirect follow process

  • Through the sign breakpoint of alloc

  • Select the Breakpoint Symbolic Breakpoint

  • Symbol breakpointalloc

  • mainIn theCJLPersonAdd a breakpoint at

Before reaching this part of the breakpoint, you need to close the symbol breakpoint above. The reason is that there are many calls to alloc, and if enabled, you cannot locate the ALLOc method of CJLPerson accurately

  • Open theAlloc symbol breakpoint

  • Continue to perform

As can be seen from the following figure, the source of alloc is located in the libobjC.a.dylib library (you need to go to Apple’s corresponding open source website to download objc source code for further exploration).

2, through thePress and hold the control+step into

Put a breakpoint on CJLPerson in main, run the program, and it will break at CJLPerson

  • Hold down thecontrolTo selectstep into⬇ ️ key

  • The following information is displayed

  • Again the nextobjc_allocSymbol breakpoint, displayed after symbol breakpointobjc_allocSource code library

(You need to go to Apple’s corresponding open source website to download objC source code for further exploration)

3. Assembly and process

  • mainIn theCJLPersonAdd a breakpoint, run the program, will break atCJLPersonlocation

  • Xcode toolbar selectionDebug –> Debug Workflow –> Always Show DisassemblyThis option always shows disassembly, that is, through assembly and flow

  • Hold down thecontrol, click on thestep into⬇️ key, go to the following figureCallq corresponds to objc_alloc

  • Hold down thecontrol, click on thestep into⬇️ key to enter and see the breakpoint broken atobjc_allocPart of the

Also, the symbol breakpoint of objc_alloc is used to find the source library (you need to go to Apple’s corresponding open source website to download objC source code for further exploration).

Note (below is the source code provided by Apple to download the address

1, Apple all open source source summary address, according to the corresponding version of the corresponding source, take MAC 10.15 as an example: macOS –> 10.15 –> select 10.15 –> search objC

2, Apple more direct source download address, directly search to download the source name, such as objc: directly search objc –> objC4 / –> select the corresponding version of ObjC