Swift: how can I create external interface for static library (public headers analog in Objective-C .h)

前端 未结 2 882
无人共我
无人共我 2020-12-15 08:37

I need to create a static library with Swift, and I need to know how can I implement interface for the library.

In Objective-C I can mark needed headers as public in

2条回答
  •  佛祖请我去吃肉
    2020-12-15 09:20

    If you want your Swift framework to expose certain classes to the interface, simply mark the 'entities' (functions, variables etc.) public:

    public class Class {}
    public var variable: Int
    public func function() { }
    

    By default, all entities have internal access.

    • public entities are intended for use as API, and can be accessed by any file that imports the module, e.g. as a framework used in several of your projects.
    • internal entities are available to the entire module that includes the definition (e.g. an app or framework target).
    • private entities are available only from within the source file where they are defined.

    Source: the official Swift blog.

提交回复
热议问题