summaryrefslogtreecommitdiff
path: root/swift/README.md
blob: 478647ecd8c9e9f9fa5e1faf17bf4f08ee899730 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Ice For Swift

[Getting started] | [Examples] | [NuGet package] | [Documentation] | [Building from source]

The [Ice framework] provides everything you need to build networked applications, including RPC, pub/sub, server deployment, and more.

Ice for Swift is the swift implementation of the Ice framework.

## Sample Code

```slice
// Slice definitions (Hello.ice)

module Demo
{
    interface Hello
    {
        void sayHello();
    }
}
```

```swift
// Client application
import Foundation
import Ice

do {
    let communicator = try Ice.initialize(CommandLine.arguments)
    defer {
        communicator.destroy()
    }

    let hello = try uncheckedCast(
        prx: communicator.stringToProxy("hello:default -h localhost -p 10000")!,
        type: HelloPrx.self)
    try hello.sayHello()
} catch {
    print("Error: \(error)\n")
    exit(1)
}
```

```swift
// Server application
import Foundation
import Ice

// Automatically flush stdout
setbuf(__stdoutp, nil)

struct Printer: Hello {
    func sayHello(current _: Ice.Current) throws {
        print("Hello World!")
    }
}

do {
    let communicator = try Ice.initialize(CommandLine.arguments)
    defer {
        communicator.destroy()
    }

    let adapter = try communicator.createObjectAdapterWithEndpoints(
        name: "Hello",
        endpoints: "default -h localhost -p 10000")
    try adapter.add(servant: HelloDisp(Printer()), id: Ice.stringToIdentity("hello"))
    try adapter.activate()
    communicator.waitForShutdown()
} catch {
    print("Error: \(error)\n")
    exit(1)
}
```

[Getting started]: https://doc.zeroc.com/ice/3.7/hello-world-application/writing-an-ice-application-with-swift
[Examples]: https://github.com/zeroc-ice/ice-demos/tree/3.7/swift
[Documentation]: https://doc.zeroc.com/ice/3.7
[Building from source]: https://github.com/zeroc-ice/ice/blob/3.7/swift/BUILDING.md
[Ice framework]: https://github.com/zeroc-ice/ice