Unified Contacts

05 July, 2014

The difference of let array and let dictionary

In Swift, let is used to declare constant and var is used to declare variable. In Objective-C, there are array and mutable array, also dictionary and mutable dictionary. Instinctively, you may think constant array is not mutable and the values inside the array is not editable. The truth is a constant array is not mutable but you may edit the values inside. However, constant dictionary is not the same as array. A constant dictionary is not mutable or editable.

I don't know why constant array is that special :(

Update:
Start from Beta 3, let array is now completely immutable, and var array is completely mutable.

Link: Swift Language Changes in Xcode 6 beta 3

No comments:

Post a Comment