Skip to main content
Skip table of contents

Swift Mapping for Parameters and Return Values

In Parameters

An in parameter is mapped to a Swift parameter with the same name; its type is the mapped Swift type.

For example, a Slice parameter string name is mapped to a Swift parameter name with type String. The rules are the same as for Fields.

Parameter Labels

The mapped method (in the proxy and skeleton) always uses the Slice parameter names as parameter labels except in one situation: when the operation has a single parameter, the mapped proxy method doesn’t use any label for this sole parameter. (But the mapped skeleton method does, as usual.).

Consider the following Slice interface:

CODE
interface Greeter
{
    string greet(string name);
}

The generated code is as follows:

SWIFT
// Client-side
public protocol GreeterPrx: Ice.ObjectPrx {}

public extension GreeterPrx {
    func greet(
        _ iceP_name: String, context: Ice.Context? = nil) async throws ->
        Swift.String {
        ...
    }
}

// Server-side
public protocol Greeter: Ice.Dispatcher {
    func greet(name: String, current: Ice.Current) async throws -> Swift.String
}

Out Parameters and Return Values

The mapping for an operation depends on how many values it returns, including out parameters and a non-void return value:

  • Zero values
    The corresponding Swift method returns nothing. For the purposes of this discussion, we're not interested in these operations.

  • One value
    The corresponding Swift method returns the mapped type, regardless of whether the Slice definition of the operation declared it as a return value or as an out parameter.

  • Multiple values
    The mapped Swift method returns a tuple. If the operation declares a return value, this value is provided as the first element of the tuple with the name returnValue.

Consider this example:

CODE
interface Example
{
    double op(int inp1, string inp2, out bool outp1, out long outp2);
}

The Slice compiler generates the following Swift code for this interface:

SWIFT
// Client-side
public protocol ExamplePrx: Ice.ObjectPrx {}

public extension ExamplePrx {
    func op(inp1: Int32, inp2: String, context: Ice.Context? = nil) async throws ->
        (returnValue: Double, outp1: Bool, outp2: Int64) {
        ...
    }
}

// Server-side
public protocol Example: Ice.Dispatcher {
    func op(inp1: Int32, inp2: tring, current: Ice.Current) async throws ->
        (returnValue: Double, outp1: Bool, outp2: Int64)
}

Optional Parameters

An optional parameter is mapped to a Swift parameter with the corresponding Swift optional type.

Consider the following operation:

SLICE
optional(1) int execute(optional(2) string p);

The corresponding proxy function is:

SWIFT
func execute(_ iceP_p: String? = nil, context: Ice.Context? = nil) async throws ->
    Int32? {
    ...
}

Mapped optional parameters get a default value (nil). As a result, if you don’t specify an argument for an optional parameter when making an invocation, the target object receives “not set” for this parameter.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.