What is import func, struct, class and @_exported in Swift?

On Apple github for Swift package manager they use

import func POSIX.isatty import func libc.strerror_r import var libc.EINVAL import var libc.ERANGE import struct PackageModel.Manifest 

source

There is also a file in which the only code in it is @_exported source

 @_exported import func libc.fileno 

Is this a Swift 3 feature? I cannot find anywhere that you can import a type into the Swift documentation and nothing at @_exported .

+5
source share
1 answer

You can import only a specific part of a module, not the entire module:

Providing more detailed restrictions whose symbols are imported - you can specify a specific submodule or a specific declaration in a module or submodule. When this verbose form is used, only the imported symbol (and not the module that declares it) becomes available in the current area.

From import declaration

For example, import func POSIX.isatty will import the isatty function from the POSIX module instead of importing the entire POSIX module (which is BIG).

The @_exported attribute begins with an underscore. This means that it is a private attribute of Swift. Not a feature, implementation detail. In short, this attribute allows you to export a symbol from another module, as if it were from your module.

+9
source

Source: https://habr.com/ru/post/1260885/


All Articles