How do I create an importable module in Swift?

前端 未结 5 1421
遇见更好的自我
遇见更好的自我 2020-12-08 06:08

I have read through Apple\'s documentation for Swift and can find nothing about how to create modules or how to define class or stucture members as private or public.

5条回答
  •  一个人的身影
    2020-12-08 06:50

    Swift 4.0

    Description from the chapter "Access Control" in the Apple book "The Swift Programming Language (Swift 4 Edition)"

    Swift provides five different access levels for entities within your code. These access levels are relative to the source file in which an entity is defined, and also relative to the module that source file belongs to.

    • open access and public access enable entities to be used within any source file from their defining module, and also in a source file from another module that imports the defining module. You typically use open or public access when specifying the public interface to a framework. The difference between open and from another module that imports the defining module. You typically use open or public access when specifying the public interface to a framework.
    • internal access enables entities to be used within any source file from their defining module, but not in any source file outside of that module. You typically use internal access when defining an app’s or a framework’s internal structure.
    • fileprivate access restricts the use of an entity to its own defining source file. Use file-private access to hide the implementation details of a specific piece of functionality when those details are used within an entire file.
    • private access restricts the use of an entity to the enclosing declaration, and to extensions of that declaration that are in the same file. Use private access to hide the implementation details of a specific piece of functionality when those details are used only within a single declaration.”

提交回复
热议问题