Understanding difference between arguments and parameters in Swift.

Jatin Mishra
Jan 31, 2024

--

This was the first confusing thing I noticed in Swift when I transitioned from Java.
Usually we have something like this, here we are using argument and parameter interchangeably.

But then I saw this, I thought what’s this???
two parameters or one?

After some confusions and research I found that this is what Swift calls as “Argument label”. In Swift the argument and parameter can be used separately in a way that the argument is responsible for the readability of the method call and parameter is used for the method body execution.

There are few variations of argument and parameter usage in Swift.

Same argument and parameter labels.

Used as createUser(name: “Jatin”)

Different argument and parameter labels.

Used as createUser(with: “Jatin”)

No argument label

Used as createUser(“Jatin”)

Do share it if you found it useful and please clap if you can!!!

Photo by Wilhelm Gunkel on Unsplash

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

--

--

Jatin Mishra
Jatin Mishra

Written by Jatin Mishra

Senior iOS Engineer with 6+ years of experience, specializing in high-performance app development and architecture optimization. Join me for special insights.

No responses yet

Write a response