xcode - How does swift infer that num1 and num2 are integers? -


i confused on how swift infers num1 , num2 integers. function accepting array of ints, true, how swift num1 , num2 related array of ints???

func mean4 (numbers: [ int ] ) -> double {  let sum = numbers.reduce(0, combine: { num1, num2 in   return num1 + num2 04: }) 

the reduce function defined as:

extension sequencetype {     public func reduce<t>(initial: t, @noescape combine: (t, self.generator.element) -> t) -> t } 

self.generator.element refers array element type, int. means num2 int. initial value 0 passed, can infer t int well.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -