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

Get your FREEapp monetisation flowchart!

Use our epic flowchart to help you find the money in your idea! If you're thinking of making an app then this is vital information!


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