UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Day 5 question. Is 'return' optional?

Forums > 100 Days of SwiftUI

In the 2nd optional examples on day 5, there are 3 functions without a 'return' statement.

func getUser() -> [String] {
    ["Taylor", "Swift"]
}

According to the quiz it's not valid Swift code unless it has a 'return.' Is the 'return' optional?

3      

Hi

if the content of the function is just one line (i.e. the thing being returned) which in this case is the array then the word return is not needed (or more accurately - the compiler is inferring it).

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.