Swift Mapping for Modules

On this page:

Default Swift Mapping

Top-level Slice modules map to Swift modules with the same name as the Slice module, while nested Slice modules are used as prefix for the mapped Swift types in that module. For example:

Slice
module M1
{
    // Definitions for M1 here...
    interface A { ... }
    module M2
    {
        // Definitions for M2 here...
        interface B { ... }
    }
}

// ...

module M1    // Reopen M1
{
    // More definitions for M1 here...
    interface C { ... }
}

This definition maps to the corresponding Swift definitions:

Swift
// In Swift module M1 

public protocol APrx {
    ... 
}

public protocol M2BPrx {
    ... 
}
public protocol CPrx { 
    ...
}

The slice2swift compiler generates import declarations and Swift module references only for Swift identifiers outside the current Swift module: references to identifiers in the same module are generated without any prefix. This way, when all your Slice definitions are inside a single Slice module, you have to option to compile the generated Swift code without creating the corresponding Swift module.

Custom Swift Mapping

You can also specify the Swift module that a top-level Slice module maps to with the swift:module:module:prefix metadata directive, for example:

Slice
["swift:module:R1:P1"]
module M1
{
    // Definitions for M1 here...
}

maps to

Swift
// In Swift module R1
... Swift identifiers with P1 prepended ...

Metadata directives such as swift:module:module:prefix do not change the contract between clients and servers, in particular the type IDs for Slice types are unaffected.


See Also