From 86de1cfd9761b1e22a6cec92ae31000c81174eed Mon Sep 17 00:00:00 2001 From: TheLittleBoy Date: Sat, 20 Sep 2014 16:15:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在Xcode6.0.1中,以下这两种写法都正确。 let emptyDictionary = Dictionary() let emptyDictionary = [String: Float]() --- source/chapter1/02_a_swift_tour.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/chapter1/02_a_swift_tour.md b/source/chapter1/02_a_swift_tour.md index 6aa0ce8f..df8f447c 100755 --- a/source/chapter1/02_a_swift_tour.md +++ b/source/chapter1/02_a_swift_tour.md @@ -93,14 +93,15 @@ occupations["Jayne"] = "Public Relations" 要创建一个空数组或者字典,使用初始化语法。 ```swift -let emptyArray = String[]() -let emptyDictionary = Dictionary() +let emptyArray = [String]() +let emptyDictionary = [String: Float]() ``` 如果类型信息可以被推断出来,你可以用`[]`和`[:]`来创建空数组和空字典——就像你声明变量或者给函数传参数的时候一样。 ```swift -shoppingList = [] // 去逛街并买点东西 +shoppingList = [] +occupations = [:] ```