Legacy Cocoa Mode

Moving forward, the classic "Toffee" platform for creating applications for the Cocoa platform is being migrated to use the new Island/Darwin compiler and tool chain back-end. This will enable better interoperability with Island and Swift Runtime objects, provide other under-the-hood benefits and improvements, and eliminate the overhead of supporting two separate tool chains for Cocoa.

Right now, the new mode is inactive, and can be enabled by explicitly setting the UseLegacyToffeeMode project setting to False. The setting currently default to True. The default will change once the new mode is fully functional and compatible, and the option will be removed completely eventually, when the legacy Cocoa mode will be discontinued (probably not until 2020).

Disabling UseLegacyToffeeMode in a Cocoa project (or project target) has the following effects:

  • The Mode will be changed to "Island" and the SubMode* to "Darwin".
  • The SDK, if not set explicitly, will be se to the origial sub-mode (e.g. "iOS", "macOS", etc.).
  • the Default Object Model Setting will be set to "Cocoa".
  • The COCOA, TOFFEE and (new) TOFFEEV2 Conditional defines will be set.
  • Reference resolving will be instructed to consider "ToffeeV2" subfolders when looking up library referendes such as Elements RTL.
  • Reference resolving will ignore references to libToffee, which is no longer required.

By the combination of these effects, existing Cocoa projects should compile and act mostly as they did before, even though they are using the newer Island compiler backend. In particular, classes and interfaces will still default to Objective-C runtime types (the only type supported by the old Cocoa mode). But there are a few differences

  • Cocoa code now has access to Island classes, including Island RTL, GoBaseLibrary and any second or third party Island libraries.
  • Island code can be intermixed within the Cocoa project seamlessly, if needed.
  • Swift Projects now reference the Island-native version of the Swift Base Library, which is relieved from some limitations of the old Cocoa compiler (such as no interfaces on structs).
  • Once available1, Cocoa code will also have access to Swift Runtime classes.

Some caveats include:

  • The ISLAND define will now be set, even for Cocoa projects. Cross-platform projects that use conditional compilation using the ISLAND and TOFFEE or COCOA defines might need to be reviewed to change the order the defines are checked or add additional checks, as necessary.

Elements RTL

Projects using Elements RTL will, by default, continue to reference a special Cocoa-based version of the library, where most types are mapped against their Cocoa counterparts (e.g. List<T> continues to map to NSArray, instead of the Island-native List<T>.

This ensures best interoperability of Elements RTL types with system APIs for Cocoa projects.

See Also


  1. Swift runtime object model support will be added once Apple Swift has stabilized its ABI, a feature promised for later in 2019.