Hello friends this article is use for developer debugging print values in LLDB debug area.
There are multiple functions available in swift
print(),debugPrint(),dump(),NSLog()
use of these functions in swift
print : print(_ items: Any..., separator: String = default, terminator: String = default)
print is use for some textual representations in debug area.
example :
print("hello friends")
Output :
hello friends
debugPrint : debugPrint(_ items: Any..., separator: String = default, terminator: String = default)
debugPrint is use for shows the instance of some textual representations in debug area.
example :
debugPrint("hello friends")
Output :
"hello friends"
dump : dump<T>(_ value: T, name: String? = default, indent: Int = default, maxDepth: Int = default, maxItems: Int = default)
dump is use for print the contents of an object via reflection like mirroring. dump prints details hierarchy.
example :
dump(["iOS","Android"])
Output :
▿ 2 elements
- "iOS"
- "Android"
NSLog : NSLog(_ format: String, _ args: CVarArg...)
NSLog is use for print the contents with timestamp. It will also print project_name along with timestamp.
example :
NSLog("hello iOS developers")
Output :
2018-09-17 15:18:10.522 DebuggerDemo[2022:4583274]hello iOS developers
print() vs dump()
Let’s create simple “Student” class
class Student{
let name = "Pratik"
let lname = "Lad"
}
now print Student() class using print() & dump()
print(Student())
Output :
__lldb_expr_81.Student
dump(Student())
Output :
▿ __lldb_expr_81.Student #0
- name: "Pratik"
- lname: "Lad"
You can see the difference of printing in debug area result. print() simple print the class name where as dump() print the whole class hierarchy.
Nice concept
ReplyDelete