【发布时间】:2022-08-22 22:29:07
【问题描述】:
在 C++ 中你可以做
int x = 5;
int &y = x;
所以x 和y 都指向同一个地方。我可以在 Swift 中做到这一点吗?
我正在编写一个具有某些功能的类,以及另一个基本上是驱动程序的类。
class Driver {
var otherClass: OtherClass
var referenceVariable: Int = otherClass.referenceVariable // how to make a reference here
...
}
或者在 Swift 中是否有更好/更语义正确的方法来做到这一点?
-
你想做什么?
-
这回答了你的问题了吗? Pointers in Swift
-
您在
otherClass中有对 OtherClass 的引用,并且可以通过这种方式访问referenceVariable。
标签: swift