Computer Science : Double

Study concepts, example questions & explanations for Computer Science

varsity tutors app store varsity tutors android store

Example Questions

Example Question #74 : Computer Science

How do we declare a method to return a Double in Swift (iOS)?

Possible Answers:

func -> Double {}

method() -> Double {}

func method -> Double {}

func method() -> Double {}

Correct answer:

func method() -> Double {}


In Swift, all methods must first say what they are. They are functions, so they are prefixed with func. Next, methods must have a name. In this case, we named it method. All methods need to specify parameters, even if there are no parameters. So, method() i.e. no parameters. Finally, we wanted to return a Double. So we set the return type using -> Double. 

Learning Tools by Varsity Tutors

Incompatible Browser

Please upgrade or download one of the following browsers to use Instant Tutoring: