iOS Functions in Swift Functions in Swift Recap: Functions

What is wrong with my code here

I cannot understand what I did wrong

functions.swift
func temperatureInFahrenheit(temperature: Double) {
    return temperature: Double
}

2 Answers

andren
andren
28,391 Points

You are defining the return type incorrectly. Specifying the type of an existing value like you are doing in your return statement is incorrect. The way you specify return types in swift is by using an arrow -> between the parenthesis and the body of the function where you specify the type, like this:

func temperatureInFahrenheit(temperature: Double) -> Double { // The "-> Double" tells Swift the return type
    return temperature
}

When returning a value in a function you must add the -> Type after the parameters! And you only have to use temperature: Double in the parameters! Just return temperature!

func temperatureInFahrenheit(temperature: Double) -> Double {
    return temperature
}