An Objective-C class implemented in Lisp and its associated subclass of standard-objc-object should be defined using the macro define-objc-class. This has a syntax similar to
with additional class options including
to specify the name of the Objective-C class.
If the superclass list is empty, then standard-objc-object is used as the default superclass, otherwise standard-objc-object must be somewhere on class precedence list or included explicitly.
For example, the following form defines a Lisp class called
and an associated Objective-C class called
(define-objc-class my-object ()
((slot1 :initarg :slot1 :initform nil))
will inherit from standard-objc-object and the class
will inherit from
. See How inheritance works for more details on inheritance.
The class returned by
is associated with the Objective-C class object for
(objc-object-pointer (find-class 'my-object))
will return a pointer to the same foreign object.
When an instance of
is made using
, an associated foreign Objective-C object of the class
is allocated by calling the class's
method and initialized by calling the instance's
Conversely, if the
method is called for the class
(or a method such as
), then an associated object of type
LispWorks Objective-C and Cocoa Interface User Guide and Reference Manual - 15 Dec 2011