gpt4 book ai didi

swift - "let"和 "static let"有什么区别?

转载 作者:搜寻专家 更新时间:2023-11-01 05:45:48 50 4
gpt4 key购买 nike

<分区>

class Foo {
let fooValue = 1
}

print(Foo.fooValue) // not work


class Bar {
static let barValue = 1
}

print(Bar.barValue) // work; print "1"

为什么?我希望 Foo 示例能够工作,因为 fooValue 的值是常量,编译时已知值和内存地址。但我需要使用关键字 static 才能工作。

50 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com