How do I create an importable module in Swift?

前端 未结 5 1408
遇见更好的自我
遇见更好的自我 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:26

    Update

    You can modularize a swift project using frameworks.

    We modularize by creating separate framework projects for each module and link them via Xcode workspace. It looks more natural when we separate the components into different projects & it also makes sure that there is only a one-way communication between modules. Developers can work/test on isolation without thinking much about other modules.

    By default classes/structs/etc created within a framework will have an internal access control type so it is only visible within the modules. In order to make it visible outside the module, you can make it public.

    More info on access controll level here


    The latest Xcode 6 beta update (beta 4) bring access control to swift

    Swift Enables Access Control

    Swift access control has three access levels:

    • private entities can only be accessed from within the source file where they are defined.
    • internal entities can be accessed anywhere within the target where they are defined.!
    • public entities can be accessed from anywhere within the target and from any other context that imports the current target’s module.

提交回复
热议问题