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

前端 未结 3 1651
北恋
北恋 2021-02-03 16:30

I created two classes Content and Bucket. Bucket contains an array of Content objects and exposes that via a public property

相关标签:
3条回答
  • 2021-02-03 17:03

    My issue was a namespace problem.

    I had declared an enum called Data and that was mucking with the Swift Data class, especially an imageData: Data property within a Core Data model.

    0 讨论(0)
  • 2021-02-03 17:05

    You have to declare the access level of the Content class public as well.

    public class Content {
       // some code
    }
    

    As stated in the 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.

    Classes are declared as internal by default, so you have to add the public keyword to make them public.

    A similar rule exists for functions as well.

    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.

    0 讨论(0)
  • 2021-02-03 17:18

    Content must be declared as public too:

    public class Content {
      …
    }
    

    Depending on your use-case you might declare Bucket as internal, too. Just omit the public keyword in this case.

    0 讨论(0)
提交回复
热议问题