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      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.