#Accessing/assigning to Objective-C fields?

1 messages · Page 1 of 1 (latest)

marble oracle
#

I need to assign an NSImage to an NSLayer field.

You can see the field in question — layer.contents — in the CALayer docs here:
https://developer.apple.com/documentation/quartzcore/calayer

And the field itself is an any type that can be explicitly assigned a CG or NSImage:
https://developer.apple.com/documentation/quartzcore/calayer/1410773-contents

These property fields aren't bound or exposed in core:sys/darwin/Foundation's Layer object. More importantly, I don't see any other objects in the bindings who expose structure fields correctly, it's all just procedure methods. Modifying the basic Layer struct nets an error because objc_class types must be zero-sized.

So how can I bind or otherwise access that field to make this assignment in Odin?

strange temple
#

Properties in Objective-C are just methods with a pre-set selector convention (unless specified otherwise)

You can either add the bindings yourself to the core:sys/darwin/Foundation package, or use https://github.com/harold-b/darwodin, which are exhaustive, emitted from the Objective-C headers themselves, if you need it. Or you can copy the bindings (https://github.com/harold-b/darwodin/blob/master/darwodin-macos-lite/darwodin/QuartzCore/CALayer.odin#L327) you need from there and place them in the sys/darwin one, fixing up type references to point to the the built-in bindings

marble oracle
#

I got it! Thank you so much, that's awesome. I assumed it was something to that effect but I couldn't figure it out for the life of me.