Debugging in Xcode Basics (Part 1)
Print Statement
You can print any object in the debug area using the print function.
Literal expressions can be added too in the print function
Literal | Type | Value |
---|---|---|
#file | String | The name of the file and module in which it appears. |
#filePath | String | The path to the file in which it appears. |
#line | Int | The line number on which it appears. |
#column | Int | The column number in which it begins. |
#function | String | The name of the declaration in which it appears. |
#dsohandle | UnsafeRawPointer | The DSO (dynamic shared object) handles in use where it appears. |
Source: https://docs.swift.org/swift-book/ReferenceManual/Expressions.html
Buildtime Swift Compiler Warnings
In the above screenshot, you can see the build time warning that can be resolved by adding @discardableResult in the function or you can treat as a warning too. (see below screenshot)
Runtime Swift Compiler Issues
Xcode Runtime Issues are reports of programming errors found at run time. Issues can be found by a variety of tools, including Address Sanitizer (ASan), Main Thread Checker (MTC), Thread Sanitizer (TSan), and Undefined Behavior Sanitizer (UBSan).
Source: Apple Doc
Debugging In Xcode With LLDB
Now we can see how the current thread’s call stack looks when we forced a crash. (see screenshot)
We can also check the stop-reason by running the “thread info” command in the debug area.
During a debugging session, we can check the call stack in the debug area too by running the command “bt“(backtrace). For more debugger commands type “help” in the debug area.