Building Ice Applications in Swift for Ice 3.7.6

This page provides important information for Swift developers.

On this page:

Prerequisites

In order to build applications with Ice in Swift, you need:

  1. The Slice to Swift compiler 
    slice2swift is a command-line tool written in C++. You need it only during development. You can install slice2swift with:

    brew install ice
  2. The Ice Framework for Swift

    You can install Carthage using Homebrew:

    brew install carthage

    Then add the Ice framework to your Cartfile:

    echo 'github "zeroc-ice/ice" ~> 3.7' >> Cartfile

    Finally tell Carthage to build and install your Cartfile frameworks and their dependencies:

    carthage update --use-xcframeworks

    The following frameworks will be built:

    Minimum Requirements

    Ice.xcframework and PromiseKit.xcframework are the minimum requirements for using Ice for Swift.

    Add Ice and PromiseKit repositories to your package descriptor dependencies:

    dependencies: [
        .package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.10.0"),
        .package(url: "https://github.com/zeroc-ice/ice-spm.git", "3.7.3" ..< "3.8.0")
    ],

    The following modules are available from Ice package:

    • Ice
    • IceGrid
    • IceStorm
    • Glacier2

    The PromiseKit package provides the PromiseKit module.

    Ice and PromiseKit modules are the minimum requirements for using Ice for Swift.

Compile Slice Files

This allows you to compile Slice files into Swift code each time you build your application. With this setup, you don't need to (and should't) put the code generated by slice2swift under source-control. 

On each target's Build Rules settings tab, click the + icon. Under Process (Source files with names matching:) enter the names of the Slice files you want to compile, typically: 

Process [Source files with names matching:]
*.ice

Add a Custom Script to run the slice2swift compiler:

Custom script:
if [ -f /usr/local/bin/slice2swift ]; then
	SLICE2SWIFT=/usr/local/bin/slice2swift
    SLICEDIR=/usr/local/share/slice2swift/slice
else
    echo "Failed to locate slice2swift compiler"
    exit 1
fi

"$SLICE2SWIFT" -I"$SLICEDIR" -I"$INPUT_FILE_DIR" --output-dir "$DERIVED_FILE_DIR" "$INPUT_FILE_PATH"

Add the path to the generated source file to the Output Files:

Output Files
$(DERIVED_FILE_DIR)/$(INPUT_FILE_BASE).swift

Swift Package Manager doesn't currently support custom build rules and you will have to manually compile your Slice definitions using the slice2swift compiler, and add the generated source files to your package sources directory.


Adding Ice Frameworks

 Xcode Application Targets

macOS

Drag the framework binaries from Carthage/Build/Mac into your application’s Xcode project. Ensure they are included in your targets' General / Embedded settings tab. 

iOS

Drag the framework binaries from Carthage/Build/iOS into your application’s Xcode project. Ensure they are included in your targets' General / Linked Frameworks and Libraries settings tab. 

Refer to the following links for additional information:

Xcode Command Line Tool Targets

Drag the framework binaries from Carthage/Build/Mac into your application’s Xcode project. Ensure they are included in your targets' General / Linked Framework and Libraries settings tab.

In the package descriptor add the Ice and PromiseKit frameworks as dependencies to your targets:

targets: [
    .target(name: "Client", dependencies: ["Ice", "PromiseKit"]),
    .target(name: "Server", dependencies: ["Ice", "PromiseKit"])
]

There are additional modules for Glacier2, IceStorm and IceGrid.


PromiseKit

The Ice API for asynchronous invocations and dispatches relies on promises provided by PromiseKit. As a result, you need to bundle the PromiseKit framework in addition to the Ice framework with your Ice-based applications.

Using the Sample Programs

Sample programs are available at the ice-demos GitHub repository. You can browse this repository to see build and usage instructions for all supported programming languages. You can clone this repository with:

git clone -b 3.7 https://github.com/zeroc-ice/ice-demos.git
cd ice-demos