How Implicit Return Types Removed that Annoying Swift Inconsistency

It took SO LONG to fix this

Steven Curtis
3 min readMar 18, 2023
Photo by Ryan Stone on Unsplash

For a long time we haven’t been living in a fair environment. It’s true: With a closure you can omit the return keyword, but you could never do the same in a function. THAT GOT FIXED!!

Difficulty: Beginner | Easy | Normal | Challenging

This article has been developed using Xcode 11.4.1, and Swift 5.2.2

The example

Most Swift ninjas (those with 6 months+ of experience, that is) know writing short and elegant code is extremely important, and helps us write easily understandable code that is a pleasure to maintain.

Closures have helped us do this for some time, I mean look at the following examples (which are all equivalent!, presuming we have let arr = [1,2,3,4,5]):

We FINALLY have parity for functions, and the following can be called through helloToTheWorld() — isn’t that awesome?!?

Click for Gist

REMEMBER THOUGH

It only works with one liners. Whack a print statement into the above to get it to be two lines and you’ll have…

--

--