官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 越西县| 平南县| 元朗区| 东乡| 敦化市| 夏邑县| 旬阳县| 洛扎县| 定兴县| 迁安市| 沙田区| 泰宁县| 上蔡县| 威远县| 正定县| 芦山县| 蕲春县| 兴海县| 江孜县| 会昌县| 遂平县| 澎湖县| 灵寿县| 荔浦县| 肥西县| 通河县| 文山县| 海口市| 邹平县| 新竹县| 通化县| 会理县| 辽源市| 许昌县| 柯坪县| 张家界市| 五指山市| 安庆市| 珠海市| 贵州省| 洱源县|