In a few cases, for instance when using nib files created by Apple's Interface Builder, it is necessary to add Objective-C instance variables to a class. This can be done using the
:objc-instance-vars
class option to define-objc-class. For example, the following class contains two instance variables, each of which is a pointer to an Objective-C foreign object:
(define-objc-class my-controller ()
()
(:objc-class-name "MyController")
(:objc-instance-vars
("widthField" objc:objc-object-pointer)
("heightField" objc:objc-object-pointer)))
Given an instance of
my-controller
, the instance variables can be accessed using the function objc-object-var-value.