GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

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 try! Swift Tokyo.

SPONSORED Ready to dive into the world of Swift? try! Swift Tokyo is the premier iOS developer conference will be happened in April 9th-11th, where you can learn from industry experts, connect with fellow developers, and explore the latest in Swift and iOS development. Don’t miss out on this opportunity to level up your skills and be part of the Swift community!

Get your ticket here

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.