[Openmcl-devel] Accessing objc properties

Gary Byers gb at clozure.com
Sun Jul 5 21:20:09 PDT 2009



On Sun, 5 Jul 2009, Neil Baylis wrote:

> I'm trying to translate the following snippet from a working objc
> program into lisp.
>
>     CALayer* lyr            = [CALayer layer];
>     lyr.opacity             = 0.5;
>
> I think I managed to create the layer by doing:
>
> (setf lyr (#/init (objc:make-objc-instance "CALayer")))
>
> I'm trying to set the opacity by writing:
>
> (setf (pref lyr :<CAL>ayer.opacity) 0.5)
>
> This yields:
>
> > Error: Record type <CAL>AYER has no field named :OPACITY.
> >        Valid field names are:
> >        (ISA _ATTR)
> > While executing: CCL::%FIND-FOREIGN-RECORD-TYPE-FIELD, in process
> Listener(6).
>
> What's the correct way for me to set this property? Why would it be
> saying that CALayer has no such field?

ObjC "properties" define things that're very much like accessor methods
in CLOS; one difference is that they're a bit more opaque (the "slots"
that those accessor methods access might be otherwise inaccessible.)

If "foo" is the name of an ObjC property on some class, then in general
#/foo will be recognized as the name of a reader method that accesses 
some state associated with the class and #/setFoo: would be the name
of the writer method that can be used to modify that state if that's
allowed.

In your case:

(#/setOpacity: lyr 0.5)


>
> Thanks,
>
> Neil Baylis
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>



More information about the Openmcl-devel mailing list