Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,520 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
}