Dynamic (id)

The Dynamic type can be used for fields, variables or parameters whose concrete type is not known at compile time.

In Oxygene and C#, the dynamic keyword can also be used to refer to this type.

Different than Object, which is the base type of all types and where a variable typed as Object provides the most strict access to only members known to be defined on the base Object class itself, a variable typed as Dynamic allows code to try and access any known (or even unknown) method or property, without any compile time checks. Only at runtime does the call get validated (and will fail, if the requested method or property does not exist).

On the Cocoa platform, the dynamic can also be referred to as id, and behaves identically to the id type provided by Objective-C or the Any and AnyObject types provided by Apple Swift.

When using the Swift language with Elements, both Any and AnyObject are aliases for dynamic.

Typical uses of Dynamic include:

  • Working with COM/IDispatch objects on .NET or Island/Windows.
  • Working with JavaScript objects on Island/WebAssembly.
  • Working with Cocoa APIs that use id.

See Also