const GLib =;

let variantDict = new GLib.VariantDict(from_asv: GLib.Variant);

GLib.VariantDict is a mutable interface to GLib.Variant dictionaries.

It can be used for doing a sequence of dictionary lookups in an efficient way on an existing GLib.Variant dictionary or it can be used to construct new dictionaries with a hashtable-like interface. It can also be used for taking existing dictionaries and modifying them in order to create new ones.

GLib.VariantDict can only be used with %G_VARIANT_TYPE_VARDICT dictionaries.

It is possible to use GLib.VariantDict allocated on the stack or on the heap. When using a stack-allocated GLib.VariantDict, you begin with a call to GLib.VariantDict.init and free the resources with a call to GLib.VariantDict.prototype.clear.

Heap-allocated GLib.VariantDict follows normal refcounting rules: you allocate it with and use GLib.VariantDict.prototype.ref and GLib.VariantDict.prototype.unref.

GLib.VariantDict.prototype.end is used to convert the GLib.VariantDict back into a dictionary-type GLib.Variant. When used with stack-allocated instances, this also implicitly frees all associated memory, but for heap-allocated instances, you must still call GLib.VariantDict.prototype.unref afterwards.

You will typically want to use a heap-allocated GLib.VariantDict when you expose it as part of an API. For most other uses, the stack-allocated form will be more convenient.

Consider the following two examples that do the same thing in each style: take an existing dictionary and look up the "count" uint32 key, adding 1 to it if it is found, or returning an error if the key is not found. Each returns the new dictionary as a floating GLib.Variant.

## Using a stack-allocated GVariantDict

|[ GVariant * add_to_count (GVariant *orig, GError **error) { GVariantDict dict; guint32 count;

g_variant_dict_init (&dict, orig); if (!g_variant_dict_lookup (&dict, "count", "u", &count)) { g_set_error (...); g_variant_dict_clear (&dict); return NULL; }

g_variant_dict_insert (&dict, "count", "u", count + 1);

return g_variant_dict_end (&dict); } ]|

## Using heap-allocated GVariantDict

|[ GVariant * add_to_count (GVariant *orig, GError **error) { GVariantDict *dict; GVariant *result; guint32 count;

dict = g_variant_dict_new (orig);

if (g_variant_dict_lookup (dict, "count", "u", &count)) { g_variant_dict_insert (dict, "count", "u", count + 1); result = g_variant_dict_end (dict); } else { g_set_error (...); result = NULL; }

g_variant_dict_unref (dict);

return result; } ]|

Since 2.40