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

我创建了两个类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.

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...