Dump in Swift

Updated 27 August 2021

Save

Swift comes with several modern features every year in the market which is the reason for the popularity of Apple. Swift programming, everyone knows about the print function to print the message at Xcode debug console and in Objective C we used the NSLog function to print the message at the console. In this blog, we are discussing how to print all properties of the values instead of just displaying the name on the message.

Xcode 8.0+, the Dump is introducing for printing the messages at the Xcode Debug console. Dumps the given object’s contents using its mirror to standard output and specified output stream.


We can use also Dump for the same purpose as we used to print() but print() only prints the class name while in the case of dump() prints the whole class hierarchy at Xcode debug console.

Syntax of Dumb:


Example of Dump

Let’s suppose we have 3 classes SchoolRegister, TeacherRegister and StudentRegister.

SchoolRegister class makes two instances of TeacherRegister and StudentRegister class as:

Now takes an instance of SchoolRegister class as;

Firstly, we checked with print() function as:

Now we have checked with Dump() function as:

Also, check with other parameters of dump() :

Used to show max items of hierarchy in the debug console

Conclusion

If you have any comments, questions, or recommendations, feel free to post them in the comment section below!

For other blogs, please click here.

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home