Language Extensions

RemObjects Silver adds a few features to the Swift language to make it fit better on all the platforms it supports. We try to keep these extensions to a minimum, and tastefully within the design aesthetics of the Swift language.

Where additional keywords are needed, we follow the C-style language convention of prefixing these with two underscores ("__") to avoid conflict with future changes to the official Swift language.

Exception Handling

Exception handling is a crucial feature on the .NET and Java/Android platforms (and frankly, also comes in very handy on the Cocoa platform as well). Silver extends the Swift 2.0's error handling syntax to also support for exception handling on all platforms, as covered in more detail in the Exceptions and Error Handling topic.

Note: Silver 8.1 provided an interim syntax for exception handling that is being deprecated moving forward, for Silver 8.2 and later, in favor of the new do/catch syntax.

Iterators

Iterators are a special type of method that provide an easy and comfortable way to implement custom Sequences.

Partial Classes

Partial Classes allow a single class (or struct) to be declared spanning multiple source files.

Static Classes

Static Classes are classes where all members are static. Silver provides a convenient shortcut to mark a class as static instead of having to mark each individual member.

Events

Support for .NET-style multi-cast Events is provided to allow Swift code to fully participate in the .NET event system.

Await

The __await keyword is supported on .NET to unwrap asynchronous calls, similar to how await works in Oxygene and C#. See the Await Expressions topic for more details.

Inline Functions

Functions can be marked with the __inline keyword to cause them to be inlined at the call site instead of being generated as separate functions in the executable. See the Inline Functions topic for more details.

External Functions

Silver introduces the __external keyword to allow the import of external APIs via P/Invokeand JNI.

Mapped Types

RemObjects Silver has full support for Mapped Types, which are inlined types useful to create cross-platform wrappers with zero overhead. While you won't often implement your own mapped types, you will likely use existing ones, for example from the Sugar library.

Aspects

Aspects are special attributes that influence how the compiler emits the final executable. In Silver they use regular Swift attributes syntax with the @ symbol. Aspects are covered in more details in their own section, including how to use them and how to create your own.

Pure Fields

New in Elements 9.3, the __field keyword works symatrical to var to declare a field inside a class ir struct. Unlike var, the field will be implemented as plain low-level field, and not as property. This distinction can be important when, for example, dealing with Refection on .NET.

 

Smaller Extensions

  • Not meant for user code, the ยก (inverted exclamation point) suffix operator can be used to mark a type as being nullable only if it is a reference type – essentially giving it the same Nullability behavior of the type name being used on its own in Oxygene or C#.
  • Silver allows named parameters in attributes, as well as attribute scope prefixes using :.
  • __out can be used similarly to inout, but parameters will be one-directional.
  • Silver supports the same attribute prefixes as Oxygene and C#, as well as a Swift-specific @main: attribute prefix for applying attributes to the entry point.

Version Notes

Support for __field is new in Elements 9.3.