Defines a class and an Objective-C class.
objc
define-objc-class name (superclass-name*) (slot-specifier*) class-option* => name
name⇩ |
A symbol naming the class to define. |
superclass-name⇩ |
A symbol naming a superclass. |
slot-specifier⇩ |
A slot description as used by cl:defclass. |
class-option⇩ |
A class option as used by cl:defclass. |
name |
A symbol naming the class to define. |
The macro define-objc-class
defines a standard-class called name which is used to implement an Objective-C class. Normal cl:defclass inheritance rules apply for slots and Lisp methods.
Each superclass-name argument specifies a direct superclass of the new class, which can be another Objective-C implementation class or any other standard-class, provided that standard-objc-object is included somewhere in the overall class precedence list. The class standard-objc-object is the default superclass if no others are specified.
slot-specifiers are standard cl:defclass slot definitions.
class-options are standard cl:defclass class options. In addition the following options are recognized:
This option makes the Objective-C superclass name of the Objective-C class defined by the | |
This options allows Objective-C instance variables to be defined for this class. Each var-spec should be a list of the form: (ivar-name ivar-type) where ivar-name is a string naming the instance variable and ivar-type is an Objective-C FLI type. The class will automatically contain all the instance variables specified by its superclasses. | |
This option allows Objective-C formal protocols to be registered as being implemented by the class. Each protocol-name should be a string naming a previously defined formal protocol (see define-objc-protocol). The class will automatically implement all protocols specified by its superclasses. |
If name is not referenced at run time and you deliver an application relying on your class, then you need to arrange for name to be retained during delivery. This can be achieved with the Delivery keyword :keep-symbols
(see the Delivery User Guide), but a more modular approach is shown in the example below.
Suppose your application relies on a class defined like this:
(objc:define-objc-class foo () () (:objc-class-name "Foo"))
If your Lisp code does not actually reference foo
at run time then you must take care to retain your class during Delivery. The best way to achieve this is to keep its name on the plist of some other symbol like this:
(setf (get 'make-a-foo 'owner-class) 'foo)
Here make-a-foo
is the only code that makes the Foo
Objective-C object, so it is the best place to retain the Lisp class foo
(that is, only if make-a-foo
is retained).
standard-objc-object
define-objc-method
define-objc-class-method
define-objc-protocol
1.4.2 Defining an Objective-C class
LispWorks Objective-C and Cocoa Interface User Guide and Reference Manual - 01 Dec 2021 19:38:32