This page explains how iink SDK lets you organize the data it works on, store content and load it again later.
MyScript iink SDK stores content using the following structures:
IINKContentPackage
- A Package is a container storing ink and its interpretation as an ordered collection of parts. It can be
saved as a file on the file system and later reloaded or shared between users.IINKContentPart
- A part corresponds to a standalone content unit that can be processed by iink SDK.
Each part has a specific type, corresponding to the type of its root block, that can be retrieved via its type
property.It is possible to get the number of parts of a given package via its partCount
property and access an individual part by calling part
and pass it
the 0-based index of the part to load.
Parts host the data iink SDK works on. As a result, it is required to use them even if you do not intend to persist data on the disk as part of your application workflow.
MyScript iink SDK uses the file system to limit the amount of RAM that is required at a given point in time, as well as to store temporary files. It also provides serialization/deserialization methods to let application save/load MyScript data, either for persistence needs or to exchange it between users.
Even if you do not intend to explicitly save any content, MyScript iink SDK requires a read/write access to at least one folder on the file system: the temporary folder, where it will output the intermediate files it is working on.
By default, iink SDK uses the folder where the package file is located. It may however be relevant (and even mandatory on certain platforms) to choose
another folder. This can be achieved by setting the value of content-package.temp-folder
in the configuration of the engine.
To create or open packages, use the openPackage:openOption:error:
method. It comes with different possible options:
IINKPackageOpenOptionExisting
to open an existing package and fail if it does not exist (default behavior).IINKPackageOpenOptionCreate
to open an existing package or create it if it does not exist.IINKPackageOpenOptionCreateNew
to ensure to create and open a package that did not previously exist.IINKPackageOpenOptionTruncateExisting
to create and open a new package, overwriting any pre-existing package at the same location.To create a new package, you can alternatively call the createPackage:error:
convenience method, which is equivalent to call
openPackage:openOption:error:
with the IINKPackageOpenOptionCreateNew
option.
Both methods take as their first parameter the name of the file corresponding to the package on the file system.
// Create a new package
var newPackage = engine.createPackage("newPackage.iink")
// Load an existing package
var existingPackage = engine.openPackage("existingPackage.iink")
MyScript iink SDK provides two distinct methods to save content:
saveWithError:
and saveToTempWithError:
, both to be called on the IINKContentPackage
instance to consider.
It is important to understand the distinction between them, as they play different roles:
saveWithError:
will serialize all data into a zip archive named after the package, whether such data is on the memory or if it was off-loaded into the
temporary folder. The resulting file is self-contained, and can be reloaded at a later point. Due to the compression, this method is rather slow.saveToTempWithError:
will save the content that was loaded into the memory to the temporary folder. As it only writes the content that was in the
memory at a given point in time and does not require compression, calling this method is much faster. It can let iink SDK recover such data if it was
forced to exit without saving to the compressed archive.The following diagram explains how iink SDK manages the memory, as well as the role of the different save operations:
-files
suffix and
located in the same folder.
Use the deletePackage:error:
method to remove an existing package from the disk. Make sure to first release all references to this package, including
parts you opened.
Parts are created and manipulated from their parent package.
To create a part, call createPart
on the parent package and pass it a string corresponding to the content type you want to assign
to its root block (it cannot be changed afterwards).
Possible options are currently “Textâ€, “Mathâ€, “Drawing, “Diagramâ€, “Raw Content†or “Text Document†(case sensitive).
To copy a part from an existing package, call clonePart
on the destination package (which can be the same as the origin package if you just
want to duplicate the part) and pass it a pointer to the part to copy.
To “move†a part from a package to another, first clone it into the new package and then delete the part from the original package.
To open a part, call part
and pass in parameter its index in its parent package (indexes start at 0). The number of parts of a given package
can be retrieved via its partCount
property.
To delete a part, call removePart
on its parent package.
You can attach metadata to both IINKContentPart
and IINKContentPackage
objects, and they will be serialized with the file.
This can prove useful to store client-specific parameters.
Use the metadata
property to store and retrieve the metadata attached to the object.
// Retrieve the metadata from a part
let metadata = part.metadata
// Set and Get (key, value) pairs
...
// Store the metadata back into the part
part.metadata = metadata;
The structure representing metadata is an IINKParameterSet
and is manipulated the exact same way as engine configuration parameters.
Let’s now see how iink SDK can render some content.