ios - Forced to use parameter names, but only some of them -
this question has answer here:
i'm new swift , i've read swift function documentation , far understand function has built way:
func funcname(param1:type, param2:type) -> return { //whatever istructions } and has called way:
funcname(1, 2); very easy, , here original apple documentation:
func halfopenrangelength(start: int, end: int) -> int { return end - start } println(halfopenrangelength(1, 10)) // prints "9" so in last example when calling halfopenrangelength function don't have specify name of parameters (start , end).
so did function in xcode:
func assegnarisposte(uno:string, due:string, tre:string, quattro:string){ button1.settitle(uno, forstate: uicontrolstate.normal) button2.settitle(due, forstate: uicontrolstate.normal) button3.settitle(tre, forstate: uicontrolstate.normal) button4.settitle(quattro, forstate: uicontrolstate.normal) } but when call way error missing argument lables 'due:tre:quattro:' in call:
assegnarisposte("davide", "andrea", "sergio", "roberto") and xcode fix imposes me way:
assegnarisposte("davide", due: tre: "andrea", "sergio", quattro: "roberto") so i'm forced place 3 of parameter names. if place first parameter (uno) throws error, have put due, tre , quattro
as far read can specify parameter names placing dash in front of parameter, , also, i'm not forced use them.
can explain me why this?
there difference between functions , methods in swift in naming, basically:
- the default naming of functions there no external parameter names.
- the default naming methods there external parameter names expect first parameter.
and can read differences between methods , functions here or here.
updated:
if don't want use external parameter names, should declare method like:
func assegnarisposte(uno:string, _ due:string, _ tre:string, _ quattro:string){ ... }
Comments
Post a Comment