加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 属性不能被声明为public,因为它的类型使用内部类型

发布时间:2020-12-14 05:58:30 所属栏目:百科 来源:网络整理
导读:我创建了两个类Content和Bucket。 Bucket包含一组Content对象,并通过public属性公开。但是,当我这样做,我收到错误: Property cannot be declared public because its type uses an internal type 对于为什么会引发错误的任何想法? 您还必须声明Content
我创建了两个类Content和Bucket。 Bucket包含一组Content对象,并通过public属性公开。但是,当我这样做,我收到错误:

Property cannot be declared public because its type uses an internal type

对于为什么会引发错误的任何想法?

您还必须声明Content类的访问级别public。
public class Content {
   // some code
}

如documentation所述:

A public variable cannot be defined as having an internal or private
type,because the type might not be available everywhere that the
public variable is used.

默认情况下,类被声明为内部,因此您必须添加public关键字才能使其公开。

函数也存在类似的规则。

A function cannot have a higher access level than its parameter types and return type,because the function could be used in situations where its constituent types are not available to the surrounding code.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读