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
Nic Clark
2,192 PointsSwift / Xcode Function Error
I can't get a function with two parameters to work e.g.
func someFunction(firstParameterName: Int, secondParameterName: Int) { // function body goes here // firstParameterName and secondParameterName refer to // the argument values for the first and second parameters }
someFunction(1, 2)
THE ERROR RETURNED IS
Playground execution failed: /var/folders/yw/d3ntrqd13jl_xd_tkg3nm5p00000gq/T/./lldb/1036/playground13.swift:13:13: error: missing argument label 'secondParameterName:' in call someFunction(1,2) ^ secondParameterName:
NOTE:
I have version 7 of Xcode running on a macbook pro which is less than 6 months old.
thanks for your help
1 Answer
Myers Carpenter
6,421 PointsSwift requires you to name the second parameter when you call your functions. So you can't write someFunction(1, 1) but rather someFunction(1, secondParameterName: 2). I believe the goal is to make it easier to read, but it feels weird you can't define add(1, 2).
More on this in Apple's Swift Docs.
Nic Clark
2,192 PointsNic Clark
2,192 Pointsthanks Myers !!!! ... that worked. I agree ... seems weird.