From 359d9acb94c95d8ccb9262be90e83a02e160018c Mon Sep 17 00:00:00 2001 From: 100mango <100mango@users.noreply.github.com> Date: Sun, 28 Jun 2015 14:05:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E8=AE=A2Implicit=20Return=20From=20Si?= =?UTF-8?q?ngle-Expression=20Clossures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/chapter2/07_Closures.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/chapter2/07_Closures.md b/source/chapter2/07_Closures.md index 806f321e..f3324d16 100755 --- a/source/chapter2/07_Closures.md +++ b/source/chapter2/07_Closures.md @@ -140,10 +140,10 @@ reversed = names.sort( { s1, s2 in return s1 > s2 } ) 单行表达式闭包可以通过隐藏`return`关键字来隐式返回单行表达式的结果,如上版本的例子可以改写为: ```swift -reversed = sorted(names, { s1, s2 in s1 > s2 } ) +reversed = names.sort( { s1, s2 in s1 > s2 } ) ``` -在这个例子中,`sorted`函数的第二个参数函数类型明确了闭包必须返回一个`Bool`类型值。 +在这个例子中,`sort(_:)`方法的第二个参数函数类型明确了闭包必须返回一个`Bool`类型值。 因为闭包函数体只包含了一个单一表达式 (`s1 > s2`),该表达式返回`Bool`类型值,因此这里没有歧义,`return`关键字可以省略。