Wednesday, 15 April 2015

xcode - Function parameter error - Missing Argument Label Anomaly - SWIFT -



xcode - Function parameter error - Missing Argument Label Anomaly - SWIFT -

i have unusual issue (which can overcome proper understanding of error).

i have little random number generator function utilize often:

func rannum(low: int, high:int) -> uint32 { var result = arc4random_uniform(uint32((high+1)-low)) + low homecoming result

}

when utilize in xcode playgrounds works fine if pass in like:

rannum(1, 10)

however, in regular swift file generates error message : missing argument label 'hi:' in call. can overcome calling function way:

rannum(1, hi:10)

apart beingness little harder read, isn't making sense why works in playgrounds why requires 2nd argument label , not both. help not understandinh appreciated.

that's called external parameter name, , default:

global functions: don't have implicit external names class/struct methods: external names automatically defined parameters after first initializers: external names automatically defined parameters

if not explicitly specified, external names take same name local parameter.

you can override prefixing local parameter name _. in case:

func rannum(low: int, _ high:int) -> uint32 { ... }

you mentioned in playground calling function works without external parameter name - may argue that:

in playground have function global function in other tests, function class/struct method

am right?

xcode function swift

No comments:

Post a Comment