ObjectClassProtocol

public protocol ObjectClassProtocol

The ObjectClassProtocol protocol exposes the methods and properties of an underlying GObjectClass instance. The default implementation of these can be found in the protocol extension below. For a concrete class that implements these methods and properties, see ObjectClass. Alternatively, use ObjectClassRef as a lighweight, unowned reference if you already have an instance you just want to use.

The class structure for the GObject type.

(C Language Example):

// Example of implementing a singleton using a constructor.
static MySingleton *the_singleton = NULL;

static GObject*
my_singleton_constructor (GType                  type,
                          guint                  n_construct_params,
                          GObjectConstructParam *construct_params)
{
  GObject *object;

  if (!the_singleton)
    {
      object = G_OBJECT_CLASS (parent_class)->constructor (type,
                                                           n_construct_params,
                                                           construct_params);
      the_singleton = MY_SINGLETON (object);
    }
  else
    object = g_object_ref (G_OBJECT (the_singleton));

  return object;
}
  • ptr

    Untyped pointer to the underlying GObjectClass instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer { get }
  • _ptr Default implementation

    Typed pointer to the underlying GObjectClass instance.

    Default Implementation

    Return the stored, untyped pointer as a typed pointer to the GObjectClass instance.

    Declaration

    Swift

    var _ptr: UnsafeMutablePointer<GObjectClass> { get }

ObjectClass Record: ObjectClassProtocol extension (methods and fields)

  • findProperty(propertyName:) Extension method

    Looks up the GParamSpec for a property of a class.

    Declaration

    Swift

    func findProperty(propertyName property_name: UnsafePointer<gchar>) -> UnsafeMutablePointer<GParamSpec>!
  • Installs new properties from an array of GParamSpecs.

    All properties should be installed during the class initializer. It is possible to install properties after that, but doing so is not recommend, and specifically, is not guaranteed to be thread-safe vs. use of properties on the same type on other threads.

    The property id of each property is the index of each GParamSpec in the pspecs array.

    The property id of 0 is treated specially by GObject and it should not be used to store a GParamSpec.

    This function should be used if you plan to use a static array of GParamSpecs and g_object_notify_by_pspec(). For instance, this class initialization:

    (C Language Example):

    enum {
      PROP_0, PROP_FOO, PROP_BAR, N_PROPERTIES
    };
    
    static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
    
    static void
    my_object_class_init (MyObjectClass *klass)
    {
      GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
    
      obj_properties[PROP_FOO] =
        g_param_spec_int ("foo", "Foo", "Foo",
                          -1, G_MAXINT,
                          0,
                          G_PARAM_READWRITE);
    
      obj_properties[PROP_BAR] =
        g_param_spec_string ("bar", "Bar", "Bar",
                             NULL,
                             G_PARAM_READWRITE);
    
      gobject_class->set_property = my_object_set_property;
      gobject_class->get_property = my_object_get_property;
      g_object_class_install_properties (gobject_class,
                                         N_PROPERTIES,
                                         obj_properties);
    }
    

    allows calling g_object_notify_by_pspec() to notify of property changes:

    (C Language Example):

    void
    my_object_set_foo (MyObject *self, gint foo)
    {
      if (self->foo != foo)
        {
          self->foo = foo;
          g_object_notify_by_pspec (G_OBJECT (self), obj_properties[PROP_FOO]);
        }
     }
    

    Declaration

    Swift

    func installProperties(nPspecs n_pspecs: CUnsignedInt, pspecs: UnsafeMutablePointer<UnsafeMutablePointer<GParamSpec>>)
  • Installs a new property.

    All properties should be installed during the class initializer. It is possible to install properties after that, but doing so is not recommend, and specifically, is not guaranteed to be thread-safe vs. use of properties on the same type on other threads.

    Note that it is possible to redefine a property in a derived class, by installing a property with the same name. This can be useful at times, e.g. to change the range of allowed values or the default value.

    Declaration

    Swift

    func installProperty(propertyID property_id: CUnsignedInt, pspec: ParamSpecProtocol)
  • listProperties(nProperties:) Extension method

    Get an array of GParamSpec* for all properties of a class.

    Declaration

    Swift

    func listProperties(nProperties n_properties: UnsafeMutablePointer<CUnsignedInt>) -> UnsafeMutablePointer<UnsafeMutablePointer<GParamSpec>>!
  • Registers property_id as referring to a property with the name name in a parent class or in an interface implemented by oclass. This allows this class to “override” a property implementation in a parent class or to provide the implementation of a property from an interface.

    Internally, overriding is implemented by creating a property of type GParamSpecOverride; generally operations that query the properties of the object class, such as g_object_class_find_property() or g_object_class_list_properties() will return the overridden property. However, in one case, the construct_properties argument of the constructor virtual function, the GParamSpecOverride is passed instead, so that the param_id field of the GParamSpec will be correct. For virtually all uses, this makes no difference. If you need to get the overridden property, you can call g_param_spec_get_redirect_target().

    Declaration

    Swift

    func overrideProperty(propertyID property_id: CUnsignedInt, name: UnsafePointer<gchar>)
  • gTypeClass Extension method

    the parent class

    Declaration

    Swift

    var gTypeClass: GTypeClass { get }