創建一個空陣列或者字典,使用初始化語法。
To create an empty array or dictionary, use the initializer syntax.
let emptyArray = [String]()
let emptyDictionary = [String: Float]()
如果型態資訊可以被推斷出來,你可以用[]和[:]來創建空陣列和空字典——就像你宣告變數或者給函式傳參數的時候一樣。
If type information can be inferred, you can write an empty array as `[]` and an empty dictionary as `[:]`—for example, when you set a new value for a variable or pass an argument to a function.
shoppingList = []
occupations = [:]
0 意見:
張貼留言