Smart debugging with Literal Expression in Swift

--

Printing logs is the most important while you are debugging. It becomes more challenging when there are different function calls involved in a feature you are debugging.
Most of the developers use random print statements to check how the code flow is behaving e.g.

print(“someFunction -> 1”)
print(“someFunction -> 2”)
and so on….

Here comes Literal Expression

Literal Expression is a source code representation of a value that can be of any possible types in Swift (Int, String, Floating-Point, Boolean, Array or dictionary etc.).

e.g. #file, #function, #line and there are many more.

Now, how to use it

Here I am taking just few basic examples that’ll help you in basic logging.

Bonus Point

When used as default-parameter, they have values of where they are evaluated i.e. the call-site

Thanks for reading.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Sudhanshu Srivastava
Sudhanshu Srivastava

Written by Sudhanshu Srivastava

I write about what I learn. Swift, Kotlin, Flutter, Social and Life.

No responses yet

Write a response