<small id='X6EBm'></small><noframes id='X6EBm'>

        <i id='X6EBm'><tr id='X6EBm'><dt id='X6EBm'><q id='X6EBm'><span id='X6EBm'><b id='X6EBm'><form id='X6EBm'><ins id='X6EBm'></ins><ul id='X6EBm'></ul><sub id='X6EBm'></sub></form><legend id='X6EBm'></legend><bdo id='X6EBm'><pre id='X6EBm'><center id='X6EBm'></center></pre></bdo></b><th id='X6EBm'></th></span></q></dt></tr></i><div id='X6EBm'><tfoot id='X6EBm'></tfoot><dl id='X6EBm'><fieldset id='X6EBm'></fieldset></dl></div>
        <legend id='X6EBm'><style id='X6EBm'><dir id='X6EBm'><q id='X6EBm'></q></dir></style></legend>
          <bdo id='X6EBm'></bdo><ul id='X6EBm'></ul>

        <tfoot id='X6EBm'></tfoot>
      1. 如何复制“字典"在斯威夫特?

        How to copy a quot;Dictionaryquot; in Swift?(如何复制“字典在斯威夫特?)
          <bdo id='hSHEy'></bdo><ul id='hSHEy'></ul>
          <tfoot id='hSHEy'></tfoot>
          1. <legend id='hSHEy'><style id='hSHEy'><dir id='hSHEy'><q id='hSHEy'></q></dir></style></legend>

            <i id='hSHEy'><tr id='hSHEy'><dt id='hSHEy'><q id='hSHEy'><span id='hSHEy'><b id='hSHEy'><form id='hSHEy'><ins id='hSHEy'></ins><ul id='hSHEy'></ul><sub id='hSHEy'></sub></form><legend id='hSHEy'></legend><bdo id='hSHEy'><pre id='hSHEy'><center id='hSHEy'></center></pre></bdo></b><th id='hSHEy'></th></span></q></dt></tr></i><div id='hSHEy'><tfoot id='hSHEy'></tfoot><dl id='hSHEy'><fieldset id='hSHEy'></fieldset></dl></div>
              <tbody id='hSHEy'></tbody>

                <small id='hSHEy'></small><noframes id='hSHEy'>

                  本文介绍了如何复制“字典"在斯威夫特?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何在 Swift 中复制字典"?

                  How to copy a "Dictionary" in Swift?

                  即获取另一个具有相同键/值但内存地址不同的对象.

                  That is, get another object with same keys/values but different memory address.

                  另外,如何在 Swift 中复制一个对象?

                  Furthermore, how to copy an object in Swift?

                  谢谢,

                  推荐答案

                  一个'Dictionary'在swift中其实是一个Struct,是一个值类型.所以复制它很简单:

                  A 'Dictionary' is actually a Struct in swift, which is a value type. So copying it is as easy as:

                  let myDictionary = ...
                  let copyOfMyDictionary = myDictionary
                  

                  复制一个对象(它是一个引用类型)有几个不同的答案.如果对象采用 NSCopying 协议,那么你可以这样做:

                  To copy an object (which is a reference type) has a couple of different answers. If the object adopts the NSCopying protocol, then you can just do:

                  let myObject = ...
                  let copyOfMyObject = myObject.copy()
                  

                  如果您的对象不符合 NSCopying 那么您可能无法复制该对象.根据对象的类,它可能会提供自己的方法来获取副本,或者如果对象没有内部私有状态,那么您可以创建一个具有相同属性的新对象.

                  If your object doesn't conform to NSCopying then you may not be able to copy the object. Depending on the object's class it may provide it's own method to get a duplicate copy, or if the object has no internal private state then you could create a new object with the same properties.

                  这篇关于如何复制“字典"在斯威夫特?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  what#39;s property copy means in Cocoa#39;s Framework?(like UITabBar#39;s items property)(Cocoa 框架中的属性副本是什么意思?(如 UITabBar 的 items 属性))
                  Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
                  SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
                  WebKit on th iPhone: is it possible to copy text to the clipboad with JavaScript(iPhone上的WebKit:是否可以使用JavaScript将文本复制到剪贴板)
                  Difference between retain and copy?(保留和复制的区别?)
                  Can`t copy file from bundle to documents directory in iOS(无法将文件从捆绑包复制到 iOS 中的文档目录)

                    <small id='G0AUX'></small><noframes id='G0AUX'>

                      1. <i id='G0AUX'><tr id='G0AUX'><dt id='G0AUX'><q id='G0AUX'><span id='G0AUX'><b id='G0AUX'><form id='G0AUX'><ins id='G0AUX'></ins><ul id='G0AUX'></ul><sub id='G0AUX'></sub></form><legend id='G0AUX'></legend><bdo id='G0AUX'><pre id='G0AUX'><center id='G0AUX'></center></pre></bdo></b><th id='G0AUX'></th></span></q></dt></tr></i><div id='G0AUX'><tfoot id='G0AUX'></tfoot><dl id='G0AUX'><fieldset id='G0AUX'></fieldset></dl></div>

                          <tbody id='G0AUX'></tbody>
                        <tfoot id='G0AUX'></tfoot><legend id='G0AUX'><style id='G0AUX'><dir id='G0AUX'><q id='G0AUX'></q></dir></style></legend>
                          • <bdo id='G0AUX'></bdo><ul id='G0AUX'></ul>