Swift Mapping for Local Interfaces

On this page:

Mapped Swift Protocol

A Slice local interface is mapped to a Swift protocol with the same name, for example:

Slice
module Ice
{
    local interface Communicator
    {
        ...
    }
}

is mapped to the Swift protocol Communicator:

Swift
// in module Ice
 
public protocol Communicator: AnyObject {
    ...
}

The delegate metadata allows you to map a local interface with a single operation to a function type with a typealias. For example:

Slice
module Ice
{
    ["delegate"] local interface ValueFactory
    {
        Value create(string type);
    }
}

is mapped to:

Swift
public typealias ValueFactory = (String) throws -> Value?

LocalObject in Swift

All Slice local interfaces implicitly derive from LocalObject, which is mapped to AnyObject in Swift.

Mapping for Local Interface Inheritance in Swift

Inheritance of local Slice interfaces is mapped to protocol inheritance in Swift. For example:

Slice
module M
{
    local interface A {}
    local interface B extends A {}
    local interface C extends A {}
    local interface D extends B, C {} 
} 

is mapped to:

Swift
public protocol A: AnyObject {}
public protocol B: A {}
public protocol C: A {}
public protocol D: B, C {}