BindingRef

public struct BindingRef : BindingProtocol, GWeakCapturing

GBinding is the representation of a binding between a property on a GObject instance (or source) and another property on another GObject instance (or target).

Whenever the source property changes, the same value is applied to the target property; for instance, the following binding:

(C Language Example):

  g_object_bind_property (object1, "property-a",
                          object2, "property-b",
                          G_BINDING_DEFAULT);

will cause the property named “property-b” of object2 to be updated every time g_object_set() or the specific accessor changes the value of the property “property-a” of object1.

It is possible to create a bidirectional binding between two properties of two GObject instances, so that if either property changes, the other is updated as well, for instance:

(C Language Example):

  g_object_bind_property (object1, "property-a",
                          object2, "property-b",
                          G_BINDING_BIDIRECTIONAL);

will keep the two properties in sync.

It is also possible to set a custom transformation function (in both directions, in case of a bidirectional binding) to apply a custom transformation from the source value to the target value before applying it; for instance, the following binding:

(C Language Example):

  g_object_bind_property_full (adjustment1, "value",
                               adjustment2, "value",
                               G_BINDING_BIDIRECTIONAL,
                               celsius_to_fahrenheit,
                               fahrenheit_to_celsius,
                               NULL, NULL);

will keep the “value” property of the two adjustments in sync; the celsius_to_fahrenheit function will be called whenever the “value” property of adjustment1 changes and will transform the current value of the property before applying it to the “value” property of adjustment2.

Vice versa, the fahrenheit_to_celsius function will be called whenever the “value” property of adjustment2 changes, and will transform the current value of the property before applying it to the “value” property of adjustment1.

Note that GBinding does not resolve cycles by itself; a cycle like

  object1:propertyA -> object2:propertyB
  object2:propertyB -> object3:propertyC
  object3:propertyC -> object1:propertyA

might lead to an infinite loop. The loop, in this particular case, can be avoided if the objects emit the GObject::notify signal only if the value has effectively been changed. A binding is implemented using the GObject::notify signal, so it is susceptible to all the various ways of blocking a signal emission, like g_signal_stop_emission() or g_signal_handler_block().

A binding will be severed, and the resources it allocates freed, whenever either one of the GObject instances it refers to are finalized, or when the GBinding instance loses its last reference.

Bindings for languages with garbage collection can use g_binding_unbind() to explicitly release a binding between the source and target properties, instead of relying on the last reference on the binding, source, and target instances to drop.

GBinding is available since GObject 2.26

The BindingRef type acts as a lightweight Swift reference to an underlying GBinding instance. It exposes methods that can operate on this data type through BindingProtocol conformance. Use BindingRef only as an unowned reference to an existing GBinding instance.

  • ptr
    Untyped pointer to the underlying `GBinding` instance.
    

    For type-safe access, use the generated, typed pointer binding_ptr property instead.

    Declaration

    Swift

    public let ptr: UnsafeMutableRawPointer!

Binding Class

  • Designated initialiser from the underlying C data type

    Declaration

    Swift

    @inlinable
    init(_ p: UnsafeMutablePointer<GBinding>)
  • Designated initialiser from a constant pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init(_ p: UnsafePointer<GBinding>)
  • Conditional initialiser from an optional pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init!(_ maybePointer: UnsafeMutablePointer<GBinding>?)
  • Conditional initialiser from an optional, non-mutable pointer to the underlying C data type

    Declaration

    Swift

    @inlinable
    init!(_ maybePointer: UnsafePointer<GBinding>?)
  • Conditional initialiser from an optional gpointer

    Declaration

    Swift

    @inlinable
    init!(gpointer g: gpointer?)
  • Conditional initialiser from an optional, non-mutable gconstpointer

    Declaration

    Swift

    @inlinable
    init!(gconstpointer g: gconstpointer?)
  • Reference intialiser for a related type that implements BindingProtocol

    Declaration

    Swift

    @inlinable
    init<T>(_ other: T) where T : BindingProtocol
  • This factory is syntactic sugar for setting weak pointers wrapped in GWeak<T>

    Declaration

    Swift

    @inlinable
    static func unowned<T>(_ other: T) -> BindingRef where T : BindingProtocol
  • Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to BindingProtocol.

    Declaration

    Swift

    @inlinable
    init<T>(cPointer: UnsafeMutablePointer<T>)
  • Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to BindingProtocol.

    Declaration

    Swift

    @inlinable
    init<T>(constPointer: UnsafePointer<T>)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to BindingProtocol.

    Declaration

    Swift

    @inlinable
    init(mutating raw: UnsafeRawPointer)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to BindingProtocol.

    Declaration

    Swift

    @inlinable
    init(raw: UnsafeMutableRawPointer)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to BindingProtocol.

    Declaration

    Swift

    @inlinable
    init(opaquePointer: OpaquePointer)