Table of Contents Previous Next
Logo
Client-Side Slice-to-Objective-C Mapping : 18.3 Mapping for Modules
Copyright © 2003-2010 ZeroC, Inc.

18.3 Mapping for Modules

Because Objective‑C does not support namespaces, a Slice module maps to a prefix for the identifiers defined inside the modules. By default, the prefix is the same as the name of the module:
module example
{
    enum Color { Red, Green, Blue };
};
With this definition, the Slice Color identifier is mapped to the Objective‑C iden­tifier exampleColor.
For nested modules, by default, the module identifiers are concatenated. For example, consider the following Slice definition:
module outer {
    module inner {
        enum Color { Red, Green, Blue };
    };
};
With this definition, the Slice identifier Color becomes outerinnerColor in Objective‑C.
You can use a metadata directive to change the default mapping to a different prefix. For example:
["objc:prefix:OUT"]
module outer {
    enum Vehicle { Car, Truck, Bicycle };

    module inner {
        enum Color { Red, Green, Blue };
    };
};
With this definition, Vehicle maps to OUTVehicle. However, Color still maps to outerinnerColor, that is, the metadata directive applies only to types defined in the outer module, but not to types that are defined in nested modules. If you want to assign a prefix for types in the nested module, you must use a sepa­rate metadata directive, for example:
["objc:prefix:OUT"]
module outer {
    enum Vehicle { Car, Truck, Bicycle };

    ["objc:prefix:IN"]
    module inner {
        enum Color { Red, Green, Blue };
    };
};
With this definition, Vehicle maps to OUTVehicle, and Color maps to INColor.
For the remainder of the examples in this chapter, we assume that Slice defini­tions are enclosed by a module Example with a ["objc:prefix:EX"] metadata directive.

Table of Contents Previous Next
Logo