gpt4 book ai didi

ios - 在扩展中有网点

转载 作者:可可西里 更新时间:2023-11-01 00:34:23 24 4
gpt4 key购买 nike

我们不能在 ViewController 的扩展中为 View 提供导出的原因是什么?

在 和它是由同一个 xib 引用的同一个类。

swift guide 中所述来自苹果:

Extensions in Swift can:

Add computed instance properties and computed type properties

Define instance methods and type methods

Provide new initializers

Define subscripts

Define and use new nested types

Make an existing type conform to a protocol

我认为正如评论中所建议的那样,它必须对内存做一些事情。虽然新的存储属性会增加该对象的内存,但计算的属性不会。

最佳答案

根据documentation ,扩展不能将存储的属性添加到类中:

Extensions can add new computed properties, but they cannot add stored properties, or add property observers to existing properties.

Outlets 是由 Storyboard填充的存储属性。因此,您不能在扩展中定义 socket 。

可以看看下面的SO question出于某种原因,不允许在扩展中存储属性。

关于ios - 在扩展中有网点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46359538/

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