Parameter Passing in Swift
Parameter passing on the server side follows the rules for the client side. Additionally, every operation receives a trailing parameter of type Current
. For example, the name
operation of the Node
interface has no parameters, but the corresponding name
method of the servant interface has a single parameter of type Current
. We will ignore this parameter for now.
The parameter-passing rules change somewhat when using the asynchronous mapping.
On this page:
Server-Side Mapping for Parameters in Swift
The servant mapping for operation parameters is the same as for proxies, except for the trailing Current parameter. To illustrate the rules for the Swift mapping, consider the following interface:
module M { interface Example { string op1(); void op2( out string sout); string op3( string sin, out string sout); optional ( 1 ) string op4(); void op5( out optional ( 1 ) string sout); optional ( 1 ) string op6( out optional ( 2 ) string sout); } } |
The generated skeleton protocol looks like this:
public protocol Example { func op1(current: Ice . Current ) throws -> Swift . String func op2(current: Ice . Current ) throws -> Swift . String func op3(sin: Swift . String , current: Ice . Current ) throws -> (returnValue: Swift . String , sout: Swift . String ) func op4(current: Ice . Current ) throws -> Swift . String ? func op5(current: Ice . Current ) throws -> Swift . String ? func op6(current: Ice . Current ) throws -> (returnValue: Swift . String ?, sout: Swift . String ?) } |
You'll notice that op1
and op2
have the same signature because the mapping rules state that an operation returning a single value shall use that type as its return value, regardless of whether the Slice operation declared it as the return type or as an out parameter. (The same is true for op4
and op5
. And when an operation returns more than one value, the proxy and servant methods return a tuple as shown above for op3
and op6
.
With other programming languages, you need to be mindful about marshaling objects returned by your operation implementation that may be modified concurrently by other threads. There is less of a concern in Swift since you typically serialize tasks to perform updates.