Photo by Ricardo Gomez Angel on Unsplash

While working with protocols in swift, you might have written a type conforming to multiple protocols.
Here comes Protocol Composition a technique to combine multiple protocols into a single representation.

How it is written:

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.

Photo by Artem Kniaz on Unsplash

Higher-Order functions; If you have some experience working in swift, you might have used it at several places in your code. A function that takes one or more function as argument is called Higher-Order function.

But here, what I am more interested in explaining is how to write your own Higher-Order function. ( It is hot question for many companies too, so stay tuned ). What I have seen in my experience that this question is put in such a way that it seems complicated when asked, which is not that tricky actually.

Let’s start with this question and answer…

There can be many possible cases when you face two different protocols with same signature of function or name of variable.

Here is the solution, use this
@_implements(protocol_name, func_or_var_to_be_renamed)
var new_name_for_func_or_var_to_be_renamed

Let’s try some sample code:


XCode scans your all methods written in your test class and tests all which start with ‘test’.
You can be simply disabled just by adding anything before ‘test’.

For example: modify it like this ‘func xyztestBusinessLogic()’ and this test wouldn’t be picked by XCTest.

Sudhanshu Srivastava

iOS Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store