斯威夫特:通过引用传递数组? [英] Swift: Pass array by reference?

查看:159
本文介绍了斯威夫特:通过引用传递数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过我的雨燕阵列 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆