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

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -