iOS Programming Cookbook
上QQ阅读APP看书,第一时间看更新

Inferring type

When closures are passed as argument like what we did in the sort function, Swift can infer the types of closure parameters and return type. In that case, we can omit the parameters and return types, as there is no need to write them. In our previous example, when we infer types, the sort function would be like this:

names.sort{ str1, str2 in 
   return str1 > str2 
} 

As you can see, the String types and the return type have been omitted.