字符串、數組和字典的賦值和複製

In Swift, many basic data types such as String, Array, and Dictionary are implemented as structures. This means that data such as strings, arrays, and dictionaries are copied when they are assigned to a new constant or variable, or when they are passed to a function or method.
在swift中,許多基本數據類型,例如字符串,數組和字典的實現都是用結構體實現的。這意味着當它們會被拷貝,當他們備用常量或者變量賦值,或者當他們被傳遞進一個函數或者方法中的時候。
This behavior is different from Foundation: NSString, NSArray, and NSDictionary are implemented as classes, not structures. Strings, arrays, and dictionaries in Foundation are always assigned and passed around as a reference to an existing instance, rather than as a copy.
這種行爲是不同於Foundation框架下的字符串,字典和數組,因爲他們不是類。在Foundation框架下,賦值和傳遞都是引用而不是拷貝。

發佈了74 篇原創文章 · 獲贊 6 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章