When writing services or function there are some things that need to be known:
- Multi threading
- Global data
Both services and functions run in a multithreaded environment. Hence all code must be thread safe.
Code is made thread safe by making sure that all global data is accessed through a synchronisation mechanism. In Swift that is done through Grand Central Dispatch (GCD).
A short example on how to do this is shown below:
Mistakes made can show up in crashes of the entire application or in users receiving websites that are incorrect, or even intended for somebody else.
Swiftfire has a logger that can be used by custom functions and sequences also.
The typical use is:
Of course the <…> should be replaced by whatever should be logged.
There are several logging levels available. Read more about these in the readme
Due to multi threading, the default filemanager should not be used. Since creating a filemanager is expensive (time & resources) a filemanager is provided in the “connection” object.
Every SFConnection has a “filemanager” entry that can be used instead of the default manager.
Swiftfire has a number of global data items. While they are not intended for use by the sequences or functions it is necessary to be aware that they exist to prevent name clashes producing unexpected results.
The following global objects exist:
(For Swiftfire v0.10.9)