swift - struct 中的 swift 类在分配期间是否通过副本传递?

标签 swift class struct pass-by-reference pass-by-value

如果我在 swift 中有一个带有类属性的结构并且我复制了该结构对象,那么类属性是通过引用复制还是传递?

最佳答案

通过引用传递。你可以测试一下。声明:

class A{}
struct B { let a = A()}

然后:

let b = B()
print("A = \(unsafeAddressOf(b.a))")//0x0000600000019450
let b_copy = b
print("A = \(unsafeAddressOf(b_copy.a))")//0x0000600000019450

关于swift - struct 中的 swift 类在分配期间是否通过副本传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41045562/

相关文章:

c - 如何将结构初始化为空?

ios - 使用未声明的类型 'UIViewController'

javascript - 在命令提示符中运行 .class 文件

C# 错误“...的类型初始值设定项抛出异常

c++ - typedef 如何代替 Procedural c++ 的 struct/class?

c - fprintf 在 C 中的使用

ios - 使用通用 Storyboard : trailing and leading spaces give wrong value 时,将 UIView 设置为使用自动布局更正设备宽度

ios - AVAudioSession 在系统声音之上播放

swift - Sprite Kit SKLabel 未显示在背景图片上

php - 如何获取类中的静态变量列表?