In Swift sometimes the underscore is there and sometimes it’s not. A bit like Schrodingers cat…(sorry, bad science joke)

So what doe it do exactly?

Well, let’s back track a little bit and talk about functions first. Any function that has some parameters passed into it MUST have those parameters names specified when the function is called.

Example Case 1:

Now sometimes the Swift 3 Underscore appears like this:

Can you spot the difference?

In the first one you had to specify “name: ” but in the second you didn’t have to, just like the good ol days of programming (or like C#).

Example Case 2:

Sometimes you have a variable that you declared but didn’t actually use. Underscore _ is a way of designing that variable and saving a teeny tiny bit of memory (for iPhone 4s users, clearly).

And those are the 2 basic cases of the underscore (at least that I remember off hand). Seen any others? Maybe you should post below and let me know!

What Does the Underscore in Swift Programming Mean?
Tagged on:             

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share This

Exhausted by your 9 - 5?

Would you prefer to work for half the time and earn double? The first step to your freedom is understanding how apps make money. Simply enter your email below and I will send you a free PDF describing the process.

If you're serious about improving your life then do not miss this opportunity.

You have subscribed! Please check your email to confirm this subscription and to receive your item!