Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Swift Functions and Optionals Functions Function Return Types

Antonio Montalvo
Antonio Montalvo
10,549 Points

Is anyone having problems with Swift Function return type ?

Several things are not working the way they should. BY THE WAY I AM USING XCODE 7.1 On the code below. First: xcode shows println has been substitute by just print. Second: missing argument label in call. It suggesting to fix including width on the second argument only. I don't get it. It shows this:

Playground execution failed: /var/folders/wh/cr0y5nzn13lc2lrjnlhjwdyh0000gn/T/./lldb/13033/playground23.swift:11:30: error: missing argument label 'width:' in call
print("Area = \(calculateArea(10, 12))")
                             ^
                                  width: 
/var/folders/wh/cr0y5nzn13lc2lrjnlhjwdyh0000gn/T/./lldb/13033/playground23.swift:14:14: error: missing argument label 'width:' in call
calculateArea(1000, 1200)
             ^
                    width: 

This is what i am trying to execute.

import UIKit

print("Swift Function")

func calculateArea(height: Int, width: Int) ->Int {
  return height * width
}

print("Area = \(calculateArea(10, 12))")


calculateArea(1000, 1200)

1 Answer

Hi,

  1. you have to change println to print as you said. This is a change since Swift 2.0 which has been released a few months back.
  2. you must add the parameter name "width" to your function call. When you have more than one parameter for a function, all of them except the first one need to have a name in the call. I don't know why this is. I accept it and enjoy the Xcode autofill function :)

Hope this helps, even if it's a bit late.