我想通过引用将Swift Array
account.chats
传递到chatsViewController.chats
(这样当我将聊天添加到account.chats
时,chatsViewController.chats
仍然指向account.chats
).也就是说,当account.chats
的长度改变时,我不希望Swift将两个数组分开.
我想通过引用将Swift Array
account.chats
传递到chatsViewController.chats
(这样当我将聊天添加到account.chats
时,chatsViewController.chats
仍然指向account.chats
).也就是说,当account.chats
的长度改变时,我不希望Swift将两个数组分开.
Swift中的 struct 是按值传递的,但可以使用inout
修饰符修改数组(参见下面的答案).类是通过引用传递的.Swift中的Array
和Dictionary
实现为 struct .