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 trialAntonio Montalvo
10,549 PointsIs 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
Kim Sorgalla
2,174 PointsHi,
- 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.
- 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.
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsBrendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsPlease post your code according to these guidelines:
https://teamtreehouse.com/community/posting-code-to-the-forum