Thursday, 15 July 2010

ios - Odd xcode error when calling defined func in Swift -



ios - Odd xcode error when calling defined func in Swift -

i have next function defined in .swift file in new project i'm creating:

func createcircle(xpos: int, ypos: int) { // code here }

for reason when seek phone call using next code xcode displays error stating "missing argument label 'ypos:' in call".

createcircle(100, 100)

the odd thing treats ypos different xpos - if include xpos: in calling function highlights line , says "cannot convert expression's type '$tf' type 'integerliteralconvertable'". next end in order phone call aforementioned function:

createcircle(100, ypos: 100)

am missing obvious or xcode beta bug?

according swift documentation

section - methods - local , external parameter names methods

"specifically, swift gives first parameter name in method local parameter name default, , gives sec , subsequent parameter names both local , external parameter names default."

judging error, seems you're using method , not function. don't need provide name first parameter must subsequent parameters behaviour can changed _ (underscore character).

class mycircle { var xpos: double = 0.0; var ypos: double = 0.0; func createcircle(x: double, _ y: double) { // insert create circle logic here. } } var cir = mycircle(); cir.createcircle(100, 100);

by using underscore subsequent parameters don't have provide label them when calling method.

ios xcode swift

No comments:

Post a Comment