我创建了两个类Content和Bucket。 Bucket包含一组Content对象,并通过public属性公开。但是,当我这样做,我收到错误:
Property cannot be declared public because its type uses an internal type
对于为什么会引发错误的任何想法?
您还必须声明Content类的访问级别public。
原文链接:https://www.f2er.com/swift/320737.htmlpublic 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.