斯威夫特:通过引用传递数组? [英] Swift: Pass array by reference?
问题描述
我想通过我的雨燕阵列
account.chats
到 chatsViewController.chats
引用(所以,当我加入聊天 account.chats
, chatsViewController.chats
仍然指向 account.chats
)。即,我不希望斯威夫特两个数组分开时长 account.chats
的变化。
I want to pass my Swift Array
account.chats
to chatsViewController.chats
by reference (so that when I add a chat to account.chats
, chatsViewController.chats
still points to account.chats
). I.e., I don't want Swift to separate the two arrays when the length of account.chats
changes.
推荐答案
我最终只是让帐户
全局变量和定义的聊天
ChatsViewController
的属性为: VAR聊天:聊天] {返回account.chats}
。有关详细信息,请参阅 Acani聊天。
I ended up just making account
a global variable and defining the chats
property of ChatsViewController
as: var chats: [Chat] { return account.chats }
. For details, see Acani Chats.
这篇关于斯威夫特:通过引用传递数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!